Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Introduction-to-Python
Submodule Introduction-to-Python added at eda4e5
2 changes: 1 addition & 1 deletion NumPy/3. Inspect an Array.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "p310env",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
61 changes: 60 additions & 1 deletion NumPy/4. Sampling Methods.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,65 @@
"Next [Module](./5.%20Math%20Functions.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.77395605 0.43887844 0.85859792 0.69736803 0.09417735 0.97562235\n",
" 0.7611397 0.78606431 0.12811363 0.45038594 0.37079802 0.92676499\n",
" 0.64386512 0.82276161 0.4434142 0.22723872 0.55458479 0.06381726\n",
" 0.82763117 0.6316644 ]\n",
" [0.75808774 0.35452597 0.97069802 0.89312112 0.7783835 0.19463871\n",
" 0.466721 0.04380377 0.15428949 0.68304895 0.74476216 0.96750973\n",
" 0.32582536 0.37045971 0.46955581 0.18947136 0.12992151 0.47570493\n",
" 0.22690935 0.66981399]\n",
" [0.43715192 0.8326782 0.7002651 0.31236664 0.8322598 0.80476436\n",
" 0.38747838 0.2883281 0.6824955 0.13975248 0.1999082 0.00736227\n",
" 0.78692438 0.66485086 0.70516538 0.78072903 0.45891578 0.5687412\n",
" 0.139797 0.11453007]\n",
" [0.66840296 0.47109621 0.56523611 0.76499886 0.63471832 0.5535794\n",
" 0.55920716 0.3039501 0.03081783 0.43671739 0.21458467 0.40852864\n",
" 0.85340307 0.23393949 0.05830274 0.28138389 0.29359376 0.66191651\n",
" 0.55703215 0.78389821]\n",
" [0.66431354 0.40638686 0.81402038 0.16697292 0.02271207 0.09004786\n",
" 0.72235935 0.46187723 0.16127178 0.50104478 0.1523121 0.69632038\n",
" 0.44615628 0.38102123 0.30151209 0.63028259 0.36181261 0.08764992\n",
" 0.1180059 0.96189766]\n",
" [0.90858069 0.69970713 0.26586996 0.96917638 0.7787509 0.71689019\n",
" 0.4493615 0.27224156 0.09639096 0.9026024 0.45577629 0.20236336\n",
" 0.30595662 0.57921957 0.17677278 0.85661428 0.75851953 0.71946296\n",
" 0.43209304 0.62730884]\n",
" [0.58409797 0.6498466 0.08444432 0.4158074 0.04161417 0.49399082\n",
" 0.32986121 0.14452419 0.10340297 0.58764457 0.17059297 0.92512012\n",
" 0.58106114 0.3468698 0.59091549 0.02280387 0.95855921 0.48230344\n",
" 0.78273523 0.08273 ]\n",
" [0.48665833 0.49070699 0.93782645 0.57172805 0.4734894 0.26697566\n",
" 0.331569 0.5206724 0.43891146 0.02161208 0.82629192 0.89616077\n",
" 0.14024909 0.55403614 0.10857574 0.67224009 0.28123378 0.65942263\n",
" 0.72699461 0.76864749]\n",
" [0.10774095 0.91601185 0.23021399 0.03741256 0.55485247 0.37092228\n",
" 0.82978974 0.80825147 0.31713889 0.9528994 0.29091784 0.51505713\n",
" 0.25596509 0.93604357 0.16460782 0.04491062 0.43509706 0.99237556\n",
" 0.89167727 0.74860802]\n",
" [0.89079249 0.89344664 0.51885836 0.31592905 0.77201243 0.66166126\n",
" 0.37365773 0.09446667 0.74678961 0.26246052 0.93681315 0.24097058\n",
" 0.12275793 0.83111267 0.15328432 0.17926831 0.59938279 0.87456204\n",
" 0.19643467 0.31032367]]\n"
]
}
],
"source": [
"import numpy as np\n",
"rng = np.random.default_rng(42) # choose any integer seed\n",
"arr = rng.random((10, 20)) \n",
"print(arr)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -427,7 +486,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "p310env",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
94 changes: 84 additions & 10 deletions NumPy/5. Math Functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[-0.5 0.91421356 1.5 0.91421356 -0.5 ]\n",
"[-0.34657359 -0.04484554 0.20273255 -0.04484554 -0.34657359]\n",
"[False False True False False]\n"
]
}
],
"source": [
"import numpy as np\n",
"arr = np.array([0, np.pi/4, np.pi/2, 3*np.pi/4, np.pi]) \n",
"math = np.sin(arr) * 2 \n",
"math2 = math - 0.5\n",
"print(math2)\n",
"math3= np.abs(math2)\n",
"math4 = np.sqrt(math3)\n",
"math5= np.log(math4)\n",
"print(math5)\n",
"mask= math5 > 0\n",
"print(mask)\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -884,10 +908,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[22.66 19.98 25.62 18.58]\n",
"[25.4 26.1 24.9 25.2 26.5]\n",
"[1 2 4 2]\n",
"8.3\n"
]
}
],
"source": [
"import numpy as np\n",
"temps = np.array([\n",
" [22.1, 23.5, 22.8, 21.9, 23.0],\n",
" [19.5, 20.1, 20.5, 19.8, 20.0],\n",
" [25.4, 26.1, 24.9, 25.2, 26.5],\n",
" [18.2, 18.5, 19.0, 18.8, 18.4]])\n",
"mean_axis1 = temps.mean(axis=1) \n",
"max_axis0 = temps.max(axis=0) \n",
"print(mean_axis1)\n",
"print(max_axis0)\n",
"outliers = np.argmax(temps, axis=1)\n",
"print(outliers)\n",
"range = temps.max() - temps.min()\n",
"print(range)"
]
},
{
"cell_type": "markdown",
Expand All @@ -913,10 +963,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[11.2 14.7 13.9 19.1 23.2 21.7 22.2]\n",
"14.5\n",
"[False False False True True True True]\n",
"4\n"
]
}
],
"source": [
"import numpy as np\n",
"inflow = np.array([1.2, 3.5, -.8, 5.2, 4.1, -1.5, 0.5])\n",
"initial = 10\n",
"result = initial + np.cumsum(inflow)\n",
"print(result)\n",
"volume = inflow[inflow > 0].sum()\n",
"print(volume)\n",
"flood = 18\n",
"mask = (initial + np.cumsum(inflow)) > flood\n",
"print(mask) \n",
"peak = np.argmax(result)\n",
"print(peak)"
]
},
{
"cell_type": "markdown",
Expand All @@ -928,7 +1002,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "p310env",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
83 changes: 73 additions & 10 deletions NumPy/7. Slicing & Indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"(24, 3)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr1 = np.linspace(1.5,5.0,72)\n",
"arr = arr1.reshape(3,24)\n",
"arr2 = arr.transpose(1, 0)\n",
"arr2.shape"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -571,10 +587,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"52\n",
"[[32 35 30]\n",
" [40 42 38]\n",
" [55 58 52]]\n",
"[28 35 48 58 68]\n"
]
}
],
"source": [
"moisture_grid = np.array([\n",
" [32, 35, 30, 28, 25],\n",
" [40, 42, 38, 35, 30],\n",
" [55, 58, 52, 48, 42],\n",
" [60, 65, 62, 58, 55],\n",
" [70, 72, 70, 68, 65]\n",
"])\n",
"value = moisture_grid[2,2]\n",
"print(value)\n",
"subbasin = moisture_grid[0:3, 0:3]\n",
"print(subbasin)\n",
"column4 = moisture_grid[:, 3]\n",
"print(column4)"
]
},
{
"cell_type": "markdown",
Expand All @@ -597,10 +639,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0. 0. 0.4875 1.755 0.2028 0. 0.7371 1.2168 0. 0.0819]\n",
"[45. 31.2]\n",
"(array([0, 1, 5, 8]),)\n",
"[12.5 45. 18.9]\n"
]
}
],
"source": [
"rain = np.array([0, 0, 12.5, 45.0, 5.2, 0, 18.9, 31.2, 0, 2.1])\n",
"inrain = rain * 0.039 \n",
"print(inrain)\n",
"heavy = rain[rain>20]\n",
"print(heavy)\n",
"norain= np.where(rain==0)\n",
"print(norain)\n",
"accurate=[2,3,6]\n",
"print(rain[accurate])"
]
},
{
"cell_type": "markdown",
Expand All @@ -619,7 +682,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "p310env",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
Loading