numpy Flashcards
create a 1 rank numpy array with elements 1, 2, 3
a = np.array([1, 2, 3])
read the output of this:
a = np.array([1, 2, 3])
a.shape
prints (3,). total rows by columns
How do you select an element from a 1 rank array?
a = np.array([1, 2, 3])
Using brackets: a[0], a[1], a[3]
how would create a rank 2 array?
specify it as a list of list
a = np.array([1,2,3], [4, 5, 6])
how would you access an element from a rank 2 array?
a = np.array([1,2,3], [4, 5, 6])
a = np.array([1,2,3], [4, 5, 6])
a[0, 0] // prints 1
a[1, 1] // prints 5
How would you create an empty array of all zeros?
for 1 rank array
a = np.zeros((3, 1))
for 2 rank array
a = np.zeros(3, 2))
What’s a rank 1 array?
an array with one axis: for example [1, 2, 1] is a rank of 1. the axis length = 3
what’s a rank 2 array?
must have two axis.
[[1, 0, 1],
[0, 1, 2]]