Skip to content

Commit

Permalink
differences for PR #1069
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 12, 2023
1 parent 7be7e44 commit c585204
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 42 deletions.
16 changes: 2 additions & 14 deletions 02-numpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ It takes a bit of getting used to,
but one way to remember the rule is that
the index is how many steps we have to take from the start to get the item we want.

![](fig/python-zero-index.svg){alt="'data' is a 3 by 3 numpy array containing row 0: \['A', 'B', 'C'\], row 1: \['D', 'E', 'F'\], androw 2: \['G', 'H', 'I'\]. Starting in the upper left hand corner, data\[0, 0\] = 'A', data\[0, 1\] = 'B',data\[0, 2\] = 'C', data\[1, 0\] = 'D', data\[1, 1\] = 'E', data\[1, 2\] = 'F', data\[2, 0\] = 'G',data\[2, 1\] = 'H', and data\[2, 2\] = 'I', in the bottom right hand corner."}
![](fig/python-zero-index.svg){alt="'data' is a 3 by 3 numpy array containing row 0: \['A', 'B', 'C'\], row 1: \['D', 'E', 'F'\], androw 2: \['G', 'H', 'I'\]. Starting in the upper left hand corner, data\[0, 0\] = 'A', data\[0, 1\] = 'B',data\[0, 2\] = 'C', data\[1, 0\] = 'D', data\[1, 1\] = 'E', data\[1, 2\] = 'F', data\[2, 0\] = 'G',data\[2, 1\] = 'H', and data\[2, 2\] = 'I',in the bottom right hand corner."}

::::::::::::::::::::::::::::::::::::::::: callout

Expand Down Expand Up @@ -374,18 +374,6 @@ and press the <kbd>Tab</kbd> key twice for a listing of what is available. You c
for example: `help(numpy.cumprod)`.


::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::: callout

## Confusing Function Names

One might wonder why the functions are called `amax` and `amin` and not `max` and `min` or why the other is called `mean` and not `amean`.
The package `numpy` does provide functions `max` and `min` that are fully equivalent to `amax` and `amin`, but they share a name with standard library functions `max` and `min` that come with Python itself.
Referring to the functions like we did above, that is `numpy.max` for example, does not cause problems, but there are other ways to refer to them that could.
In addition, text editors might highlight (color) these functions like standard library function, even though they belong to NumPy, which can be confusing and lead to errors.
Since there is no function called `mean` in the standard library, there is no function called `amean`.

::::::::::::::::::::::::::::::::::::::::::::::::::

When analyzing data, though,
Expand Down Expand Up @@ -597,7 +585,7 @@ using NumPy's `vstack` and `hstack` functions for vertical and horizontal stacki
```python
import numpy

A = numpy.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
A = numpy.array([[1,2,3], [4,5,6], [7, 8, 9]])
print('A = ')
print(A)

Expand Down
4 changes: 2 additions & 2 deletions 03-matplotlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ If we want to change this, we can use the `set_ylim(min, max)` method of each 'a
for example:

```python
axes3.set_ylim(0, 6)
axes3.set_ylim(0,6)
```

Update your plotting code to automatically set a more appropriate scale.
Expand All @@ -216,7 +216,7 @@ Update your plotting code to automatically set a more appropriate scale.
# One method
axes3.set_ylabel('min')
axes3.plot(numpy.amin(data, axis=0))
axes3.set_ylim(0, 6)
axes3.set_ylim(0,6)
```

:::::::::::::::::::::::::
Expand Down
2 changes: 1 addition & 1 deletion 04-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ print(repeats)

1. `[2, 4, 6, 8, 10, 2, 4, 6, 8, 10]`
2. `[4, 8, 12, 16, 20]`
3. `[[2, 4, 6, 8, 10], [2, 4, 6, 8, 10]]`
3. `[[2, 4, 6, 8, 10],[2, 4, 6, 8, 10]]`
4. `[2, 4, 6, 8, 10, 4, 8, 12, 16, 20]`

The technical term for this is *operator overloading*:
Expand Down
10 changes: 5 additions & 5 deletions 06-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ for filename in filenames:
inflammation-01.csv
```

![](fig/03-loop_49_1.png){alt='Output from the first iteration of the for loop. Three line graphs showing the daily average, maximum and minimum inflammation over a 40-day period for all patients in the first dataset.'}
![](fig/03-loop_49_1.png){alt='Output from the first iteration of the for loop. Three line graphs showing the daily average,maximum and minimum inflammation over a 40-day period for all patients in the first dataset.'}

```output
inflammation-02.csv
```

![](fig/03-loop_49_3.png){alt='Output from the second iteration of the for loop. Three line graphs showing the daily average, maximum and minimum inflammation over a 40-day period for all patients in the seconddataset.'}
![](fig/03-loop_49_3.png){alt='Output from the second iteration of the for loop. Three line graphs showing the daily average,maximum and minimum inflammation over a 40-day period for all patients in the seconddataset.'}

```output
inflammation-03.csv
```

![](fig/03-loop_49_5.png){alt='Output from the third iteration of the for loop. Three line graphs showing the daily average, maximum and minimum inflammation over a 40-day period for all patients in the thirddataset.'}
![](fig/03-loop_49_5.png){alt='Output from the third iteration of the for loop. Three line graphs showing the daily average,maximum and minimum inflammation over a 40-day period for all patients in the thirddataset.'}

The plots generated for the second clinical trial file look very similar to the plots for
the first file: their average plots show similar "noisy" rises and falls; their maxima plots
Expand Down Expand Up @@ -161,7 +161,7 @@ Use each of the files once to generate a dataset containing values averaged over

```python
filenames = glob.glob('inflammation*.csv')
composite_data = numpy.zeros((60, 40))
composite_data = numpy.zeros((60,40))
for filename in filenames:
# sum each new file's data into composite_data as it's read
#
Expand All @@ -181,7 +181,7 @@ import numpy
import matplotlib.pyplot

filenames = glob.glob('inflammation*.csv')
composite_data = numpy.zeros((60, 40))
composite_data = numpy.zeros((60,40))

for filename in filenames:
data = numpy.loadtxt(fname = filename, delimiter=',')
Expand Down
9 changes: 9 additions & 0 deletions 07-cond.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ runs only when certain conditions are true.

We can ask Python to take different actions, depending on a condition, with an `if` statement:

::::::::::::::::::::::::::::::::::::::: instructor

The following example will lead to a syntax error in the Python prompt, as it seems to expect exactly one top-level statement per invocation.
Removing `print('done')` from the example will fix the problem.

IPython executes the example from a single prompt without throwing an error.

::::::::::::::::::::::::::::::::::::::::::::::::::

```python
num = 37
if num > 100:
Expand Down
6 changes: 3 additions & 3 deletions 08-func.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ Inside a function, one can read the value of such global variables:

```python
def print_temperatures():
print('temperature in Fahrenheit was:', temp_fahr)
print('temperature in Kelvin was:', temp_kelvin)
print('temperature in Fahrenheit was:', temp_fahr)
print('temperature in Kelvin was:', temp_kelvin)

temp_fahr = 212.0
temp_kelvin = fahr_to_kelvin(temp_fahr)
Expand Down Expand Up @@ -286,7 +286,7 @@ let's use NumPy to create a matrix of 0's
and then offset its values to have a mean value of 3:

```python
z = numpy.zeros((2, 2))
z = numpy.zeros((2,2))
print(offset_mean(z, 3))
```

Expand Down
4 changes: 2 additions & 2 deletions 10-defensive.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ The range of each time series is represented as a pair of numbers,
which are the time the interval started and ended.
The output is the largest range that they all include:

![](fig/python-overlapping-ranges.svg){alt='Graph showing three number lines and, at the bottom, the interval that they overlap.'}
![](fig/python-overlapping-ranges.svg){alt='Graph showing three number lines and, at the bottom,the interval that they overlap.'}

Most novice programmers would solve this problem like this:

Expand Down Expand Up @@ -505,7 +505,7 @@ and for each one,
give an example of input that will make that assertion fail.

```python
def get_total_cars(values):
def get_total(values):
assert len(values) > 0
for element in values:
assert int(element)
Expand Down
12 changes: 6 additions & 6 deletions 12-cmdline.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def main():
print(row_mean)

if __name__ == '__main__':
main()
main()
```

and run that:
Expand Down Expand Up @@ -393,7 +393,7 @@ def main():
print(row_mean)

if __name__ == '__main__':
main()
main()
```

and here it is in action:
Expand Down Expand Up @@ -460,7 +460,7 @@ def main():
print(val)

if __name__ == '__main__':
main()
main()
```

This works:
Expand Down Expand Up @@ -523,7 +523,7 @@ def process(filename, action):
print(val)

if __name__ == '__main__':
main()
main()
```

This is four lines longer than its predecessor,
Expand Down Expand Up @@ -621,7 +621,7 @@ def process(filename, action):
print(val)

if __name__ == '__main__':
main()
main()
```

Let's try it out:
Expand Down Expand Up @@ -994,7 +994,7 @@ def main():

def count_file(filename):
"""count the number of lines in a file"""
f = open(filename, 'r')
f = open(filename,'r')
nlines = len(f.readlines())
f.close()
return(nlines)
Expand Down
Empty file modified fig/generate_figures.py
100755 → 100644
Empty file.
Empty file modified fig/optimize_svg.py
100755 → 100644
Empty file.
Empty file modified files/code/gen_inflammation.py
100755 → 100644
Empty file.
Binary file modified files/code/python-novice-inflammation-code.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion files/code/readings_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def process(filename, action):
print(val)

if __name__ == '__main__':
main()
main()
16 changes: 8 additions & 8 deletions md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"config.yaml" "651e83c85f369ffb595f341f331ded7d" "site/built/config.yaml" "2023-04-21"
"index.md" "902f643a91093ef85fac7ec2d4319f6b" "site/built/index.md" "2023-05-12"
"episodes/01-intro.md" "6193d753b39a08e6b99b70715dff3da9" "site/built/01-intro.md" "2023-04-21"
"episodes/02-numpy.md" "1b9c4000cea628f84024abab49012a06" "site/built/02-numpy.md" "2023-11-07"
"episodes/03-matplotlib.md" "3bb8e6088285f01152e2e24da6f36fbc" "site/built/03-matplotlib.md" "2023-11-07"
"episodes/04-lists.md" "d1768916dafc023eeb2f3838932b6289" "site/built/04-lists.md" "2023-11-07"
"episodes/02-numpy.md" "68ea94506815ee991a9c3a9ee43dce6b" "site/built/02-numpy.md" "2023-11-12"
"episodes/03-matplotlib.md" "8f745014ad7c43958c0c29e0e1747d0a" "site/built/03-matplotlib.md" "2023-11-12"
"episodes/04-lists.md" "537e8d8d3fc4c345d370e71ef075b5b4" "site/built/04-lists.md" "2023-11-12"
"episodes/05-loop.md" "434dd980212b1065d576fdcdc9c2a5ca" "site/built/05-loop.md" "2023-07-28"
"episodes/06-files.md" "eda3d2e5ff2a23f37048631427cb4f48" "site/built/06-files.md" "2023-11-07"
"episodes/07-cond.md" "fd57543b12adffc501df36b1b0835a22" "site/built/07-cond.md" "2023-04-21"
"episodes/08-func.md" "ca1da7a3d21d6b8dee6a1e52d35e8d84" "site/built/08-func.md" "2023-11-10"
"episodes/06-files.md" "76c4d7453d98142b7abd99dc940f82a8" "site/built/06-files.md" "2023-11-12"
"episodes/07-cond.md" "5893669dae47d856b571e3ce5df613ca" "site/built/07-cond.md" "2023-11-12"
"episodes/08-func.md" "29038efab439eb82eb884f84a3974041" "site/built/08-func.md" "2023-11-12"
"episodes/09-errors.md" "9eb44385622246a7b9e5e51ab0057c81" "site/built/09-errors.md" "2023-04-21"
"episodes/10-defensive.md" "bb24615f90c0d508b20c68ec4640ca45" "site/built/10-defensive.md" "2023-11-10"
"episodes/10-defensive.md" "ec03726df2cfcbdb806f72c88f27e584" "site/built/10-defensive.md" "2023-11-12"
"episodes/11-debugging.md" "2376a87cad5c1f039796f7315a223aff" "site/built/11-debugging.md" "2023-04-21"
"episodes/12-cmdline.md" "6364192fd0440c6834d837055705d34b" "site/built/12-cmdline.md" "2023-11-10"
"episodes/12-cmdline.md" "cdfb6c453dbda6dab1314f0e365b5829" "site/built/12-cmdline.md" "2023-11-12"
"instructors/additional_material.md" "8032d13185179bda24bbc3d90ed22936" "site/built/additional_material.md" "2023-04-21"
"instructors/extra_exercises.md" "3cf917b8a4324afbfc26db087018a3be" "site/built/extra_exercises.md" "2023-04-21"
"instructors/instructor-notes.md" "a492a732a51a4f3601b440636aa569f5" "site/built/instructor-notes.md" "2023-04-21"
Expand Down

0 comments on commit c585204

Please sign in to comment.