@@ -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.
0 commit comments