Numpy

Overview

Teaching: 30 min
Exercises: 30 min
Questions
  • 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

  1. 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.

  2. Create an array 5x5 and reorder the rows based on the values of the first column

  3. Same as before but ordering the columns based on the order of the first row.

  4. Use numpy.sort() and check that this function is doing something different from the exercises above.

  5. Multiply a 5x3 matrix by a 3x2 matrix (real matrix product)

  6. 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.