You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/python_by_example.md
+15-18Lines changed: 15 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,8 +142,6 @@ In fact, a package is just a directory containing
142
142
In fact, you can find and explore the directory for NumPy on your computer
143
143
easily enough if you look around.
144
144
145
-
The directory can be different based on the system of the machine and the version of python.
146
-
147
145
You can check the location of your `__init__.py` for NumPy in python by running the code:
148
146
149
147
```{code-block} ipython
@@ -154,15 +152,6 @@ import numpy as np
154
152
print(np.__file__)
155
153
```
156
154
157
-
For example, on this machine, it's located in
158
-
159
-
```{code-block} ipython
160
-
:class: no-execute
161
-
162
-
anaconda3/lib/python3.9/site-packages/numpy/
163
-
```
164
-
165
-
166
155
#### Subpackages
167
156
168
157
```{index} single: Python; Subpackages
@@ -172,7 +161,9 @@ Consider the line `ϵ_values = np.random.randn(100)`.
172
161
173
162
Here `np` refers to the package NumPy, while `random` is a **subpackage** of NumPy.
174
163
175
-
Subpackages are just packages that are subdirectories of another package. For instance, you can find folder `random` under the directory of NumPy.
164
+
Subpackages are just packages that are subdirectories of another package.
165
+
166
+
For instance, you can find folder `random` under the directory of NumPy.
176
167
177
168
### Importing Names Directly
178
169
@@ -263,7 +254,9 @@ Let's study some parts of this program in more detail.
263
254
264
255
Consider the statement `ϵ_values = []`, which creates an empty list.
265
256
266
-
Lists are a *native Python data structure* used to group a collection of objects. Items in lists are ordered, and duplicates are allowed in lists.
257
+
Lists are a *native Python data structure* used to group a collection of objects.
258
+
259
+
Items in lists are ordered, and duplicates are allowed in lists.
267
260
268
261
For example, try
269
262
@@ -410,7 +403,9 @@ plt.plot(ϵ_values)
410
403
plt.show()
411
404
```
412
405
413
-
A while loop will keep executing the code block delimited by indentation until the condition (```i < ts_length```) is satisfied. It means that the programme will keep adding values to the list ```ϵ_values``` until ```i``` equals ```ts_length```:
406
+
A while loop will keep executing the code block delimited by indentation until the condition (```i < ts_length```) is satisfied.
407
+
408
+
In this case, the program will keep adding values to the list ```ϵ_values``` until ```i``` equals ```ts_length```:
414
409
415
410
```{code-cell} python3
416
411
i == ts_length #the ending condition for the while loop
@@ -465,7 +460,7 @@ operating system.
465
460
Notice that we added a legend to the plot --- a feature you will be asked to
466
461
use in the exercises.
467
462
468
-
## Exercises and Solutions
463
+
## Exercises
469
464
470
465
Now we turn to exercises. It is important that you complete them before
471
466
continuing, since they present new concepts we will need.
@@ -559,7 +554,9 @@ plt.legend()
559
554
plt.show()
560
555
```
561
556
562
-
Note:`f'$\\alpha = {α}$'` in the solution is an application of [f-String](https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings), which allows you to use `{}` to contain an expression. The contained expression will be evaluated, and the result will be placed into the string.
557
+
Note: `f'$\\alpha = {α}$'` in the solution is an application of [f-String](https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings), which allows you to use `{}` to contain an expression.
558
+
559
+
The contained expression will be evaluated, and the result will be placed into the string.
563
560
564
561
565
562
```{solution-end}
@@ -739,10 +736,10 @@ for i in range(n):
739
736
u, v = np.random.uniform(), np.random.uniform()
740
737
741
738
# check whether the point falls within the boundary
0 commit comments