Numpy
Overview
Teaching: 30 min
Exercises: 30 minQuestions
Key question (FIXME)
Objectives
Learn how to create and manipulate multidimensional arrays in numpy
The Notebook
The material for this episode is on this notebook:
3_Numpy [WVU Research Computing].ipynb
Exercises
-
Create a vector with 100 zeros, using
sys.getsizeof()
get the size of the array. Compute the size of the array using the.size
and.itemsize
properties and compute the extra overhead of a numpy object. -
Create an array 5x5 and reorder the rows based on the values of the first column
-
Same as before but ordering the columns based on the order of the first row.
-
Use
numpy.sort()
and check that this function is doing something different from the exercises above. -
Multiply a 5x3 matrix by a 3x2 matrix (real matrix product)
-
Verify why those two lines produces different results:
print(sum(range(5),-1))
print(np.sum(range(5),-1))
Key Points
NumPy is the main package for dealing with homogeneous multidimensional arrays.