@@ -156,28 +156,6 @@ Since `weight_lb` doesn't "remember" where its value came from,
156156it isn't automatically updated when ` weight_kg ` changes.
157157This is different from the way spreadsheets work.
158158
159- > ## What's inside the box? {.challenge}
160- >
161- > Draw diagrams showing what variables refer to what values after each statement in the following program:
162- >
163- > ~~~ {.python}
164- > weight = 70.5
165- > age = 35
166- > # Take a trip to the planet Neptune
167- > weight = weight * 1.14
168- > age = age + 20
169- > ~~~
170-
171- > ## Sorting out references {.challenge}
172- >
173- > What does the following program print out?
174- >
175- > ~~~ {.python}
176- > first, second = 'Grace', 'Hopper'
177- > third, fourth = second, first
178- > print third, fourth
179- > ~~~
180-
181159Just as we can assign a single value to a variable, we can also assign an array of values
182160to a variable using the same syntax. Let's re-run ` numpy.loadtxt ` and save its result:
183161
@@ -332,39 +310,6 @@ small is:
332310 [ 2. 2. 1. 1.]]
333311~~~
334312
335- > ## Slicing strings {.challenge}
336- >
337- > A section of an array is called a ** slice** .
338- > We can take slices of character strings as well:
339- >
340- > ~~~ {.python}
341- > element = 'oxygen'
342- > print 'first three characters:', element[0:3]
343- > print 'last three characters:', element[3:6]
344- > ~~~
345- >
346- > ~~~ {.output}
347- > first three characters: oxy
348- > last three characters: gen
349- > ~~~
350- >
351- > What is the value of `element[:4]`?
352- > What about `element[4:]`?
353- > Or `element[:]`?
354- >
355- > What is `element[-1]`?
356- > What is `element[-2]`?
357- > Given those answers,
358- > explain what `element[1:-1]` does.
359-
360- > ## Thin slices {.challenge}
361- >
362- > The expression `element[3:3]` produces an **empty string**,
363- > i.e., a string that contains no characters.
364- > If `data` holds our array of patient data,
365- > what does `data[3:3, 4:4]` produce?
366- > What about `data[3:3, :]`?
367-
368313Arrays also know how to perform common mathematical operations on their values.
369314The simplest operations with data are arithmetic:
370315add, subtract, multiply, and divide.
@@ -658,6 +603,59 @@ the graphs will actually be squeezed together more closely.)
658603> If you ever see Python code online using a NumPy function with ` np `
659604> (for example, ` np.loadtxt(...) ` ), it's because they've used this shortcut.
660605
606+ > ## Check your understanding {.challenge}
607+ >
608+ > Draw diagrams showing what variables refer to what values after each statement in the following program:
609+ >
610+ > ~~~ {.python}
611+ > mass = 47.5
612+ > age = 122
613+ > mass = mass * 2.0
614+ > age = age - 20
615+ > ~~~
616+
617+ > ## Sorting out references {.challenge}
618+ >
619+ > What does the following program print out?
620+ >
621+ > ~~~ {.python}
622+ > first, second = 'Grace', 'Hopper'
623+ > third, fourth = second, first
624+ > print third, fourth
625+ > ~~~
626+
627+ > ## Slicing strings {.challenge}
628+ >
629+ > A section of an array is called a [slice](reference.html#slice).
630+ > We can take slices of character strings as well:
631+ >
632+ > ~~~ {.python}
633+ > element = 'oxygen'
634+ > print 'first three characters:', element[0:3]
635+ > print 'last three characters:', element[3:6]
636+ > ~~~
637+ >
638+ > ~~~ {.output}
639+ > first three characters: oxy
640+ > last three characters: gen
641+ > ~~~
642+ >
643+ > What is the value of `element[:4]`?
644+ > What about `element[4:]`?
645+ > Or `element[:]`?
646+ >
647+ > What is `element[-1]`?
648+ > What is `element[-2]`?
649+ > Given those answers,
650+ > explain what `element[1:-1]` does.
651+
652+ > ## Thin slices {.challenge}
653+ >
654+ > The expression `element[3:3]` produces an [empty string](reference.html#empty-string),
655+ > i.e., a string that contains no characters.
656+ > If `data` holds our array of patient data,
657+ > what does `data[3:3, 4:4]` produce?
658+ > What about `data[3:3, :]`?
661659
662660> ## Check your understanding: plot scaling {.challenge}
663661>
0 commit comments