numpy Flashcards

1
Q

create a 1 rank numpy array with elements 1, 2, 3

A

a = np.array([1, 2, 3])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

read the output of this:
a = np.array([1, 2, 3])

a.shape

A

prints (3,). total rows by columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you select an element from a 1 rank array?

a = np.array([1, 2, 3])

A

Using brackets: a[0], a[1], a[3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how would create a rank 2 array?

A

specify it as a list of list

a = np.array([1,2,3], [4, 5, 6])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how would you access an element from a rank 2 array?

a = np.array([1,2,3], [4, 5, 6])

A

a = np.array([1,2,3], [4, 5, 6])

a[0, 0] // prints 1
a[1, 1] // prints 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you create an empty array of all zeros?

A

for 1 rank array

a = np.zeros((3, 1))

for 2 rank array

a = np.zeros(3, 2))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s a rank 1 array?

A

an array with one axis: for example [1, 2, 1] is a rank of 1. the axis length = 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what’s a rank 2 array?

A

must have two axis.

[[1, 0, 1],
[0, 1, 2]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly