Closed mdpiper closed 1 year ago
Some sample code from a notebook I made in class.
import numpy as np
n_rows = 4
n_cols = 5
a = np.arange(n_rows*n_cols)
a
b = a.reshape(n_rows, n_cols)
b
b.shape
# What are the values in the first column?
b[:,0]
# What are the values in the first row?
b[0,:]
nx = 4
ny = 3
nz = 2
c = np.arange(nx*ny*nz)
c
d = c.reshape(nz, ny, nx)
d
d.shape
# Slice the array to show the first *z* level.
d[0, :, :]
In the Python lessons, we should introduce nD array shape--what are rows and what are columns, and how to index them--with simple rectangular examples that can be printed and viewed in tabular form.