Skip to content

Commit 630b670

Browse files
author
giumas
committed
applied changes after committee review
1 parent 11dd709 commit 630b670

File tree

3 files changed

+158
-271
lines changed

3 files changed

+158
-271
lines changed

COMP_000_Intro_to_NumPy.ipynb

Lines changed: 24 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"cell_type": "markdown",
2020
"metadata": {},
2121
"source": [
22-
"The efficient storage and manipulation of numerical arrays is often critical when processing ocean data. This notebook will present a specialized Python package for handling such numerical arrays: [NumPy](https://www.numpy.org/) ."
22+
"The efficient storage and manipulation of numerical arrays is often critical when processing ocean data. This notebook will present a specialized Python package for handling such numerical arrays: [NumPy](https://www.numpy.org/)."
2323
]
2424
},
2525
{
@@ -42,7 +42,7 @@
4242
"cell_type": "markdown",
4343
"metadata": {},
4444
"source": [
45-
"NumPy (short for Numerical Python) is centered around a powerful N-dimensional array object, but also contains other useful capabilities like linear algebra, Fourier transform, functions to create random numbers, etc."
45+
"NumPy (short for Numerical Python) is centered around a powerful N-dimensional array object, but also provides other useful capabilities like linear algebra, Fourier transform, functions to create random numbers, etc."
4646
]
4747
},
4848
{
@@ -58,7 +58,7 @@
5858
"cell_type": "markdown",
5959
"metadata": {},
6060
"source": [
61-
"Before starting to use `numpy`, you have to execute the following cell that, together with code introduced in the past notebooks, imports `numpy` with the commonly-adopted short name of `np`:"
61+
"Before starting to use `numpy`, you have to execute the following cell. Together with code introduced in the past notebooks, this imports `numpy` and assign it the commonly-adopted short name of `np`:"
6262
]
6363
},
6464
{
@@ -106,14 +106,14 @@
106106
"cell_type": "markdown",
107107
"metadata": {},
108108
"source": [
109-
"## Creating an Array with Zero Values"
109+
"## Creating an Array Filled with Zeros "
110110
]
111111
},
112112
{
113113
"cell_type": "markdown",
114114
"metadata": {},
115115
"source": [
116-
"The first `numpy` function that we introduce is [`zeros()`](https://www.numpy.org/devdocs/reference/generated/numpy.zeros.html?#numpy.zeros). When a single integer value is passed, this function creates an 1D array containing the passed number of zeros:"
116+
"The first `numpy` function that we introduce is [`zeros()`](https://www.numpy.org/devdocs/reference/generated/numpy.zeros.html?#numpy.zeros). When a single integer is passed, this function creates an 1D array with a number of zero equal to the passed value:"
117117
]
118118
},
119119
{
@@ -130,9 +130,9 @@
130130
"cell_type": "markdown",
131131
"metadata": {},
132132
"source": [
133-
"It is also possible to create multi-dimensional array by passing a [`tuple`](https://docs.python.org/3.6/library/stdtypes.html?#tuples).\n",
133+
"It is also possible to create multi-dimensional array by passing a [`tuple`](https://docs.python.org/3.6/library/stdtypes.html?#tuples). Each value in the `tuple` define the array size for each dimension.\n",
134134
"\n",
135-
"Thus, the following code creates a 2D array with 3 rows and 8 columns passing `(3, 8)`:"
135+
"Thus, the following code creates a 2D array with 8 rows and 2 columns passing `(8, 2)`:"
136136
]
137137
},
138138
{
@@ -141,7 +141,7 @@
141141
"metadata": {},
142142
"outputs": [],
143143
"source": [
144-
"arr = np.zeros((3, 8))\n",
144+
"arr = np.zeros((8, 2))\n",
145145
"print(arr)"
146146
]
147147
},
@@ -216,6 +216,13 @@
216216
"print(\"Array dimensions: %d\" % arr.ndim)"
217217
]
218218
},
219+
{
220+
"cell_type": "markdown",
221+
"metadata": {},
222+
"source": [
223+
"The number of elements along each of the axes is the **length** of the axes."
224+
]
225+
},
219226
{
220227
"cell_type": "markdown",
221228
"metadata": {},
@@ -354,7 +361,7 @@
354361
"cell_type": "markdown",
355362
"metadata": {},
356363
"source": [
357-
"The `zeros()` is just one of the several functions available to create an array in `numpy`. \n",
364+
"The `zeros()` function is just one of the several ways to create an array in `numpy`. \n",
358365
"\n",
359366
"For instance, to create an array of a given shape, but initialized with a specific value (e.g., `8.0`), you can use the [`full()`](https://www.numpy.org/devdocs/reference/generated/numpy.full.html) function:"
360367
]
@@ -373,7 +380,7 @@
373380
"cell_type": "markdown",
374381
"metadata": {},
375382
"source": [
376-
"If you want to create an array filled with a linear sequence of values, you may use the [`arange()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html) function or the [`linspace()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html) function by selecting the one that fulfills your specific needs:"
383+
"If you want to create an array filled with a sequence of values, you may use the [`arange()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html) function or the [`linspace()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html) function by selecting the one that fulfills your specific needs:"
377384
]
378385
},
379386
{
@@ -382,7 +389,7 @@
382389
"metadata": {},
383390
"outputs": [],
384391
"source": [
385-
"arr = np.arange(start=0, stop=40, step=8) # arange excludes the `stop` value\n",
392+
"arr = np.arange(start=0, stop=40, step=8) # the `stop` value is not included\n",
386393
"print(arr)"
387394
]
388395
},
@@ -392,7 +399,7 @@
392399
"metadata": {},
393400
"outputs": [],
394401
"source": [
395-
"arr = np.linspace(start=0, stop=40, num=5)\n",
402+
"arr = np.linspace(start=0, stop=40, num=5) # the `stop` value is included\n",
396403
"print(arr)"
397404
]
398405
},
@@ -501,7 +508,9 @@
501508
"cell_type": "markdown",
502509
"metadata": {},
503510
"source": [
504-
"One of the advantages of using `numpy` arrays in place of `list` containers is the many mathematical and statistical methods available in NumPy."
511+
"Numpy arrays have many efficient mathematical and statistical methods. This is one of the motivations to use them in place of `list` containers.\n",
512+
"\n",
513+
"The cell below shows how to use some of these methods. If you want to learn more about them, visit [this Numpy page](https://www.numpy.org/devdocs/reference/arrays.ndarray.html#calculation)."
505514
]
506515
},
507516
{
@@ -550,7 +559,7 @@
550559
"temp_list = [11.2, 11.0, 13.7, 16.0, 16.1, 16.2, 16.1]\n",
551560
"\n",
552561
"temp_arr = np.array(temp_list)\n",
553-
"avg_temp = temp_arr.mean()\n",
562+
"mean_temp = temp_arr.mean()\n",
554563
"min_temp = temp_arr.min()\n",
555564
"max_temp = temp_arr.max()\n",
556565
"print(\"The average value is %f\" % (mean_temp, ))\n",
@@ -559,7 +568,7 @@
559568
"\n",
560569
"# plot creation\n",
561570
"plt.plot(temp_arr, color='orange', marker='o', label='data')\n",
562-
"plt.axhline(y=avg_temp, color='green', linestyle='dashed', label='avg')\n",
571+
"plt.axhline(y=mean_temp, color='green', linestyle='dashed', label='avg')\n",
563572
"plt.axhline(y=min_temp, color='blue', linestyle='dotted', label='min')\n",
564573
"plt.axhline(y=max_temp, color='red', linestyle='dotted', label='max')\n",
565574
"plt.title(\"Temperature\") \n",
@@ -910,101 +919,6 @@
910919
"***"
911920
]
912921
},
913-
{
914-
"cell_type": "markdown",
915-
"metadata": {},
916-
"source": [
917-
"## Array Views and Copies"
918-
]
919-
},
920-
{
921-
"cell_type": "markdown",
922-
"metadata": {},
923-
"source": [
924-
"<img align=\"left\" width=\"6%\" style=\"padding-right:10px;\" src=\"images/key.png\">\n",
925-
"\n",
926-
"Array slicing returns views rather than copies of the array data."
927-
]
928-
},
929-
{
930-
"cell_type": "markdown",
931-
"metadata": {},
932-
"source": [
933-
"The relevant implication is that, if you modify a sub-array, the original array is modified too!"
934-
]
935-
},
936-
{
937-
"cell_type": "markdown",
938-
"metadata": {},
939-
"source": [
940-
"If we extract the temperature row as a sub-array and modify it (by assigning a common value), the original `data_arr` will change too:"
941-
]
942-
},
943-
{
944-
"cell_type": "code",
945-
"execution_count": null,
946-
"metadata": {},
947-
"outputs": [],
948-
"source": [
949-
"# Create a two-dimensional data array\n",
950-
"sal_list = [34.4, 34.1, 33.6, 31.7, 31.3, 31.2, 31.0]\n",
951-
"temp_list = [11.2, 11.0, 13.7, 16.0, 16.1, 16.2, 16.1]\n",
952-
"data_arr = np.array([sal_list, temp_list])\n",
953-
"print(\"data array before:\")\n",
954-
"print(data_arr)\n",
955-
"\n",
956-
"# Slice and modify the resulting sub-array\n",
957-
"temp_arr = data_arr[1, :]\n",
958-
"temp_arr[0] = -9999.9\n",
959-
"print(\"temperature sub-array:\")\n",
960-
"print(temp_arr)\n",
961-
"print(\"data array after:\")\n",
962-
"print(data_arr)"
963-
]
964-
},
965-
{
966-
"cell_type": "markdown",
967-
"metadata": {},
968-
"source": [
969-
"This default behavior is quite useful when you handle large array since you can access sub-arrays without copying the underlying data."
970-
]
971-
},
972-
{
973-
"cell_type": "markdown",
974-
"metadata": {},
975-
"source": [
976-
"If you need a copy of a specific array or sub-array, you can explicitly copy the data using the [`copy()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.copy.html) method:"
977-
]
978-
},
979-
{
980-
"cell_type": "code",
981-
"execution_count": null,
982-
"metadata": {},
983-
"outputs": [],
984-
"source": [
985-
"# Create a two-dimensional data array\n",
986-
"sal_list = [34.4, 34.1, 33.6, 31.7, 31.3, 31.2, 31.0]\n",
987-
"temp_list = [11.2, 11.0, 13.7, 16.0, 16.1, 16.2, 16.1]\n",
988-
"data_arr = np.array([sal_list, temp_list])\n",
989-
"print(\"before:\")\n",
990-
"print(data_arr)\n",
991-
"\n",
992-
"# Slice, MAKE A COPY, and modify the resulting sub-array\n",
993-
"temp_arr = data_arr[1, :].copy()\n",
994-
"temp_arr[0] = -9999.9\n",
995-
"print(\"temperature sub-array:\")\n",
996-
"print(temp_arr)\n",
997-
"print(\"after:\")\n",
998-
"print(data_arr)"
999-
]
1000-
},
1001-
{
1002-
"cell_type": "markdown",
1003-
"metadata": {},
1004-
"source": [
1005-
"---"
1006-
]
1007-
},
1008922
{
1009923
"cell_type": "markdown",
1010924
"metadata": {},

COMP_001_Adopting_NumPy_in_Class_Methods.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"cell_type": "markdown",
2020
"metadata": {},
2121
"source": [
22-
"The task of this notebook is to use a NumPy array in the previously-coded `WaterLevels` class for storing the data. But first, please execute the following initialization code."
22+
"The task of this notebook is to use a NumPy array in the previously-coded `WaterLevels` class to store the data. But first, please execute the following initialization code."
2323
]
2424
},
2525
{

0 commit comments

Comments
 (0)