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: _episodes/01-numpy.md
+8-7Lines changed: 8 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,9 +19,9 @@ keypoints:
19
19
- "Variables are created on demand whenever a value is assigned to them."
20
20
- "Use `print(something)` to display the value of `something`."
21
21
- "The expression `array.shape` gives the shape of an array."
22
-
- "Use `array[x, y]` to select a single element from an array."
22
+
- "Use `array[x, y]` to select a single element from a 2D array."
23
23
- "Array indices start at 0, not 1."
24
-
- "Use `low:high` to specify a slice that includes the indices from `low` to `high-1`."
24
+
- "Use `low:high` to specify a `slice` that includes the indices from `low` to `high-1`."
25
25
- "All the indexing and slicing that works on arrays also works on strings."
26
26
- "Use `# some kind of explanation` to add comments to programs."
27
27
- "Use `numpy.mean(array)`, `numpy.max(array)`, and `numpy.min(array)` to calculate simple statistics."
@@ -30,6 +30,7 @@ keypoints:
30
30
---
31
31
In this lesson we will learn how to manipulate the inflammation dataset with Python. But before we discuss how to deal with many data points, we will show how to store a single value on the computer.
32
32
33
+
33
34
The line below [assigns](reference.html#assignment) the value `55` to a [variable](reference.html#variable)`weight_kg`:
34
35
35
36
~~~
@@ -169,7 +170,7 @@ Importing a library is like getting a piece of lab equipment out of a storage lo
169
170
Libraries provide additional functionality to the basic Python package,
170
171
much like a new piece of equipment adds functionality to a lab space. Just like in the lab, importing too many libraries
171
172
can sometimes complicate and slow down your programs - so we only import what we need for each program.
172
-
Once you've imported the library,
173
+
Once we've imported the library,
173
174
we can ask the library to read our data file for us:
174
175
175
176
~~~
@@ -308,7 +309,7 @@ because they have the same part-and-whole relationship.
308
309
309
310
If we want to get a single number from the array,
310
311
we must provide an [index]({{ page.root }}/reference/#index) in square brackets,
311
-
just as we do in math:
312
+
just as we do in math when referring to an element of a matrix. Our inflammation data has two dimensions, so we will need to use two indices to refer to a value:
312
313
313
314
~~~
314
315
print('first value in data:', data[0, 0])
@@ -558,7 +559,7 @@ standard deviation: 4.61383319712
558
559
>
559
560
> How did we know what functions NumPy has and how to use them?
560
561
> If you are working in the IPython/Jupyter Notebook there is an easy way to find out.
561
-
> If you type the name of something with a full-stop then you can use tab completion
562
+
> If you type the name of something followed by a dot, then you can use tab completion
562
563
> (e.g. type `numpy.` and then press tab)
563
564
> to see a list of all functions and attributes that you can use. After selecting one you
564
565
> can also add a question mark (e.g. `numpy.cumprod?`) and IPython will return an
@@ -573,7 +574,7 @@ One way to do this is to create a new temporary array of the data we want,
573
574
then ask it to do the calculation:
574
575
575
576
~~~
576
-
patient_0 = data[0, :] # 0 on the first axis, everything on the second
577
+
patient_0 = data[0, :] # 0 on the first axis (rows), everything on the second (columns)
577
578
print('maximum inflammation for patient 0:', patient_0.max())
578
579
~~~
579
580
{: .python}
@@ -584,7 +585,7 @@ maximum inflammation for patient 0: 18.0
584
585
{: .output}
585
586
586
587
Everything in a line of code following the '#' symbol is a
587
-
[comment]({{ page.root }}/reference/#comment) that is ignored by the computer.
588
+
[comment]({{ page.root }}/reference/#comment) that is ignored by Python.
588
589
Comments allow programmers to leave explanatory notes for other
Copy file name to clipboardExpand all lines: _episodes/02-loop.md
+24-29Lines changed: 24 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ exercises: 0
5
5
questions:
6
6
- "How can I do the same operations on many different values?"
7
7
objectives:
8
-
- "Explain what a for loop does."
9
-
- "Correctly write for loops to repeat simple calculations."
8
+
- "Explain what a `for` loop does."
9
+
- "Correctly write `for` loops to repeat simple calculations."
10
10
- "Trace changes to a loop variable as the loop runs."
11
-
- "Trace changes to other variables as they are updated by a for loop."
11
+
- "Trace changes to other variables as they are updated by a `for` loop."
12
12
keypoints:
13
13
- "Use `for variable in sequence` to process the elements of a sequence one at a time."
14
-
- "The body of a for loop must be indented."
14
+
- "The body of a `for` loop must be indented."
15
15
- "Use `len(thing)` to determine the length of something that contains other values."
16
16
---
17
17
@@ -34,7 +34,7 @@ word = 'lead'
34
34
{: .python}
35
35
36
36
We can access a character in a string using its index. For example, we can get the first
37
-
character of the word 'lead', by using word[0]. One way to print each character is to use
37
+
character of the word `'lead'`, by using `word[0]`. One way to print each character is to use
38
38
four `print` statements:
39
39
40
40
~~~
@@ -151,18 +151,13 @@ The numbers in the diagram denote which loop cycle the character was printed in
151
151
We can call the [loop variable]({{ page.root }}/reference/#loop-variable) anything we like,
152
152
but there must be a colon at the end of the line starting the loop,
153
153
and we must indent anything we want to run inside the loop. Unlike many other languages, there is no
154
-
command to signify the end of the loop body (e.g. end for); what is indented after the for statement belongs to the loop.
154
+
command to signify the end of the loop body (e.g. `end for`); what is indented after the `for` statement belongs to the loop.
155
155
156
156
157
-
> ## What's in a name?
157
+
> ## What's in a name?{.callout}
158
158
>
159
-
> In the example above, the loop variable was given the name `char`
160
-
> as a mnemonic; it is short for 'character'.
161
-
> 'Char' is not a keyword in Python that pulls the characters
162
-
> from words or strings.
163
-
> In fact when a similar loop is run over a list rather than a word,
164
-
> the output would be each member of that list printed in order,
165
-
> rather than the characters.
159
+
>
160
+
> In the example above, the loop variable was given the name `char` as a mnemonic; it is short for 'character'. 'Char' is not a keyword in Python that pulls the characters from words or strings. In fact when a similar loop is run over a list rather than a word, the output would be each member of that list printed in order, rather than the characters.
166
161
>
167
162
> ~~~
168
163
> elements = ['oxygen', 'nitrogen', 'argon']
@@ -178,10 +173,7 @@ command to signify the end of the loop body (e.g. end for); what is indented aft
178
173
> ~~~
179
174
> {: .output}
180
175
>
181
-
> We can choose any name we want for variables.
182
-
> We might just as easily have chosen the name `banana`
183
-
> for the loop variable,
184
-
> as long as we use the same name when we invoke the variable inside the loop:
176
+
> We can choose any name we want for variables. We might just as easily have chosen the name `banana` for the loop variable, as long as we use the same name when we invoke the variable inside the loop:
185
177
>
186
178
> ~~~
187
179
> word = 'oxygen'
@@ -200,9 +192,7 @@ command to signify the end of the loop body (e.g. end for); what is indented aft
200
192
> ~~~
201
193
> {: .output}
202
194
>
203
-
> It is a good idea to choose variable names
204
-
> that are meaningful so that it is easier
205
-
> to understand what the loop is doing.
195
+
> It is a good idea to choose variable names that are meaningful, otherwise it would be more difficult to understand what the loop is doing.
206
196
{: .callout}
207
197
208
198
Here's another loop that repeatedly updates a variable:
@@ -278,14 +268,19 @@ so we should always use it when we can.
278
268
279
269
> ## From 1 to N
280
270
>
281
-
> Python has a built-in function called `range` that creates a sequence of numbers. Range can
282
-
> accept 1-3 parameters. If one parameter is input, range creates an array of that length,
283
-
> starting at zero and incrementing by 1. If 2 parameters are input, range starts at
284
-
> the first and ends just before the second, incrementing by one. If range is passed 3 parameters,
285
-
> it starts at the first one, ends just before the second one, and increments by the third one. For
286
-
> example,
287
-
> `range(3)` produces the numbers 0, 1, 2, while `range(2, 5)` produces 2, 3, 4,
288
-
> and `range(3, 10, 3)` produces 3, 6, 9.
271
+
> Python has a built-in function called `range` that creates a sequence of numbers. `range` can
272
+
> accept 1, 2, or 3 parameters.
273
+
>
274
+
> * If one parameter is given, `range` creates an array of that length,
275
+
> starting at zero and incrementing by 1.
276
+
> For example, `range(3)` produces the numbers `0, 1, 2`.
277
+
> * If two parameters are given, `range` starts at
278
+
> the first and ends just before the second, incrementing by one.
279
+
> For example, `range(2, 5)` produces `2, 3, 4`.
280
+
> * If `range` is given 3 parameters,
281
+
> it starts at the first one, ends just before the second one, and increments by the third one.
0 commit comments