Skip to content

Commit df8a106

Browse files
committed
minor updates to NB2
1 parent 0f038a1 commit df8a106

File tree

4 files changed

+87
-65
lines changed

4 files changed

+87
-65
lines changed

.DS_Store

2 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ ENV/
8989
# Rope project settings
9090
.ropeproject
9191

92-
.DS_Store
92+
.DS_Store
93+
.DS_Store

notebook2_arrays/py_exploratory_comp_2.ipynb

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@
128128
"x = np.arange(20, 30)\n",
129129
"print(x)\n",
130130
"print(x[0:5])\n",
131-
"print(x[:5]) # same as previous one\n",
131+
"print(x[:5]) # same as previous one\n",
132132
"print(x[3:7])\n",
133-
"print(x[2:9:2]) # step is 2"
133+
"print(x[2:9:2]) # step is 2"
134134
]
135135
},
136136
{
137137
"cell_type": "markdown",
138138
"metadata": {},
139139
"source": [
140-
"You can also start at the end and count back. Generally, the index of the end is not known. You can find out how long the array is and access the last value by typing `x[len(x) - 1]` but it would be inconvenient to have to type `len(arrayname)` all the time. Luckily, there is a shortcut: `x[-1]` is the same as `x[len(x) - 1]` represents the last value in the array. For example:"
140+
"You can also start at the end and count back. Generally, the index of the end is not known. You can find out how long the array is and access the last value by typing `x[len(x) - 1]` but it would be inconvenient to have to type `len(arrayname)` all the time. Luckily, there is a shortcut: `x[-1]` is the same as `x[len(x) - 1]` and represents the last value in the array. For example:"
141141
]
142142
},
143143
{
@@ -158,7 +158,7 @@
158158
"metadata": {},
159159
"source": [
160160
"You can assign one value to a range of an array by specifying a range of indices, \n",
161-
"or you can assign an array to a range of another array, as long as the ranges have equal length. In the last example below, the first 5 values of `x` (specified as `x[0:5]`) are given the values `[40, 42, 44, 46, 48]`."
161+
"or you can assign an array to a range of another array, as long as the ranges have the same length. In the last example below, the first 5 values of `x` (specified as `x[0:5]`) are given the values `[40, 42, 44, 46, 48]`."
162162
]
163163
},
164164
{
@@ -180,7 +180,7 @@
180180
"metadata": {},
181181
"source": [
182182
"### Exercise 1, <a name=\"back1\"></a> Arrays and indices\n",
183-
"Create an array of zeros with length 20. Change the first 5 values to 10. Change the next 10 values to a sequence starting at 12 and increasig with steps of 2 to 30 - do this with one command. Set the final 5 values to 30. Plot the value of the array on the $y$-axis vs. the index of the array on the $x$-axis. Draw vertical dashed lines at $x=4$ and $x=14$ (i.e., the section between the dashed lines is where the line increases from 10 to 30). Set the minimum and maximum values of the $y$-axis to 8 and 32 using the `ylim` command."
183+
"Create an array of zeros with length 20. Change the first 5 values to 10. Change the next 10 values to a sequence starting at 12 and increasig with steps of 2 to 30 (do this with one command). Set the final 5 values to 30. Plot the value of the array on the $y$-axis vs. the index of the array on the $x$-axis. Draw vertical dashed lines at $x=4$ and $x=14$ (i.e., the section between the dashed lines is where the line increases from 10 to 30). Set the minimum and maximum values of the $y$-axis to 8 and 32 using the `ylim` command."
184184
]
185185
},
186186
{
@@ -333,8 +333,8 @@
333333
"* the first column of `x`\n",
334334
"* the third row of `x`\n",
335335
"* the last two columns of `x`\n",
336-
"* the four values in the upper right-hand corner of `x`\n",
337-
"* the four values at the center of `x`\n",
336+
"* the 2 by 2 block of values in the upper right-hand corner of `x`\n",
337+
"* the 2 by 2 block of values at the center of `x`\n",
338338
"\n",
339339
"`x = np.array([[4, 2, 3, 2],\n",
340340
" [2, 4, 3, 1],\n",
@@ -361,7 +361,7 @@
361361
"metadata": {},
362362
"source": [
363363
"### Visualizing two-dimensional arrays\n",
364-
"Two-dimensonal arrays can be visualized with the `plt.matshow` function. In the example below, the array is very small (only 4 by 4), but it illustrates the general principle. A colorbar is added as a legend. The ticks in the colorbar are specified to be 2, 4, 6, and 8. Note that the first row of the matrix (with index 0), is plotted at the top, which corresponds to the location of the first row in the matrix."
364+
"Two-dimensonal arrays can be visualized with the `plt.matshow` function. In the example below, the array is very small (only 4 by 4), but it illustrates the general principle. A colorbar is added as a legend. The ticks in the colorbar are specified to be 2, 4, 6, and 8. Note that the first row of the array (with index 0), is plotted at the top, which corresponds to the location of the first row in the array."
365365
]
366366
},
367367
{
@@ -402,7 +402,7 @@
402402
"metadata": {},
403403
"source": [
404404
"### Exercise 3, <a name=\"back3\"></a> Create and visualize an array\n",
405-
"Create an array of size 10 by 10. The upper left-hand quadrant of the array should get the value 4, the upper right-hand quadrant the value 3, the lower right-hand quadrant the value 2 and the lower left-hand quadrant the value 1. First create an array of 10 by 10 using the `zeros` command, then fill each quadrant by specifying the correct index ranges. Note that the first index is the row number. The second index runs from left to right. Visualize the array using `matshow`. It should give a red, yellow, light blue and dark blue box (clock-wise starting from upper left) when you use the default `jet` colormap."
405+
"Create an array of size 10 by 10. Set the upper left-hand quadrant of the array should to 4, the upper right-hand quadrant to 3, the lower right-hand quadrant t0 2 and the lower left-hand quadrant to 1. First create an array of 10 by 10 using the `zeros` command, then fill each quadrant by specifying the correct index ranges. Visualize the array using `matshow`. It should give a red, yellow, light blue and dark blue box (clock-wise starting from upper left) when you use the `jet` colormap."
406406
]
407407
},
408408
{
@@ -424,9 +424,9 @@
424424
"metadata": {},
425425
"source": [
426426
"### Exercise 4, <a name=\"back4\"></a> Create and visualize a slightly fancier array\n",
427-
"Consider the image shown below, which roughly shows the letters TU. You are asked to create an array that represents the same TU. First create a zeros array of 11 rows and 17 columns. Give the background value 0, the letter T value -1, and the letter U value +1. <a name=\"back4\"></a>\n",
427+
"Consider the image shown below, which roughly shows the letters TU. You are asked to create an array that represents the same TU. First create a zeros array of 11 rows and 17 columns. Give the background value 0, the letter T value -1, and the letter U value +1. Use the `jet` colormap. <a name=\"back4\"></a>\n",
428428
"\n",
429-
"<img src= \"https://raw.githubusercontent.com/mbakker7/exploratory_computing_with_python/master/notebook2_arrays/tufig.png\" width=\"500px\" />"
429+
"![](tufig.png)"
430430
]
431431
},
432432
{
@@ -477,12 +477,13 @@
477477
"outputs": [],
478478
"source": [
479479
"a = 4\n",
480-
"print(a < 4)\n",
481-
"print(a <= 4) # a is smaller than or equal to 4\n",
482-
"print(a == 4) # a is equal to 4. Note that there are 2 equal signs\n",
483-
"print(a >= 4) \n",
484-
"print(a > 4)\n",
485-
"print(a != 4) # a is not equal to 4"
480+
"print('the value of a is', a)\n",
481+
"print('a < 4: ', a < 4)\n",
482+
"print('a <= 4:', a <= 4) # a is smaller than or equal to 4\n",
483+
"print('a == 4:', a == 4) # a is equal to 4. Note that there are 2 equal signs\n",
484+
"print('a >= 4:', a >= 4) \n",
485+
"print('a > 4: ', a > 4)\n",
486+
"print('a != 4:', a != 4) # a is not equal to 4"
486487
]
487488
},
488489
{
@@ -526,7 +527,7 @@
526527
"cell_type": "markdown",
527528
"metadata": {},
528529
"source": [
529-
"The statement `data<3` returns an array of type `boolean` that has the same length as the array `data` and for each item in the array it is either `True` or `False`. The cool thing is that this array of `True` and `False` values can be used to specify the indices of an array:"
530+
"The statement `data < 3` returns an array of type `boolean` that has the same length as the array `data` and for each item in the array it is either `True` or `False`. The cool thing is that this array of `True` and `False` values can be used to specify the indices of an array:"
530531
]
531532
},
532533
{
@@ -581,7 +582,7 @@
581582
"cell_type": "markdown",
582583
"metadata": {},
583584
"source": [
584-
"### Exercise 5, <a name=\"back5\"></a> Replace high and low in an array\n",
585+
"### Exercise 5, <a name=\"back5\"></a> Replace high and low values in an array\n",
585586
"Create an array for variable $x$ consisting of 100 values from 0 to 20. Compute $y=\\sin(x)$ and plot $y$ vs. $x$ with a blue line. Next, replace all values of $y$ that are larger than 0.5 by 0.5, and all values that are smaller than $-$0.75 by $-$0.75, and plot the modified $y$ values vs. $x$ using a red line on the same graph. "
586587
]
587588
},
@@ -912,7 +913,7 @@
912913
"name": "python",
913914
"nbconvert_exporter": "python",
914915
"pygments_lexer": "ipython3",
915-
"version": "3.6.5"
916+
"version": "3.7.0"
916917
},
917918
"varInspector": {
918919
"cols": {

0 commit comments

Comments
 (0)