My questions are related to the lesson that introduces NumPy Analyzing Patient Data.
Question 1:
You have a 1D array a:
a = numpy.array([2,4,6,8,10,12])
print a
produces:
array([ 2, 4, 6, 8, 10, 12])
How can you select the last three elements, i.e., 8, 10, 12?
-
a[4:] -
a[4:8] -
a[3:] -
a[3,4,5]
Question 2:
You have a 2D array b:
b = numpy.array([[1,2,3,4],[5,6,7,8]])
print b
produces:
array([[1, 2, 3, 4],
[5, 6, 7, 8]])
How can you check the maximum value in the second and last row?
-
b[1].max() -
b[:,1].max() -
b[1,:].max() -
b.max()[1]
Discussion of the answers and possible misconceptions:
-
OK - demonstrates a possible shorter notation, i.e.,
b[1]is the same asb[1,:] -
wrong - one can confuse the C/F order
-
OK
-
wrong - default behavior for
array.max()is calculating one value for all array