Key Ideas
- Creating
nparrays - Slicing and reshaping arrays
- Operations on arrays such as broadcasting
In-Class Activity
- Download broadcast.py and study it until you understand it fully. The program illustrates the concept of broadcasting.
Active Learning
Work through np_tutorial2.py and then do the following:
- Create a vector
Zwith values ranging from 10 to 49. - Reverse
Z. - Create a 3x3 matrix
Mwith values ranging from 0 to 8. - Create a 3x3x3 array
Rwith random values. - Create a 3x3 identity matrix.
- Can you figure out what the following code produces without running it first?
Z = np.zeros((5,5)) Z += np.arange(5) print(Z)