NumPy Flashcards

Numpy practice

1
Q

How does a NumPy array display when it is printed?

A

[‘val1’ ‘val2’ ‘val3’]
strings with delimiters but no commas between.

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

What does a NumPy matrix look like when printed?

A

[[1 2 3]
[4 5 6]
[7 8 9]]
Stacked list of lists, no commas between the sublists.

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

What is the linspace calculation?

A

np.linspace(x1, x2, n)
(x2-x1)/(n-1)
i.e.
np.linspace(10, 20, 3)
(20-10)/(3-1)
10/2 = 5
print(np.linspace(10,20,3)) = [10. 15. 20.]
note: the output is decimals

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

Describe the np.arange(x, y, z) function.

A

arange or a range function creates a range where x is the starting value, y-1 is the ending value and z is the step.

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

Can you use the reshape(x,y) module on an array with an odd number of values?

A

No, it will throw an error.

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

What is the default base for the NumPy log function?

A

e

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

What does np.eye(x) do?

A

It creates an identity matrix with x by x rows and columns.
An identity matrix is a matrix where all values are 0 except for 1s running through the true diagonal.

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

Give an example of calling from a numpy array based on a conditional operation

A

var = np.array(1, 2, 4, 8, 9)
print(var[var>4])
[8 9]

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

Describe how to format a numpy array.

A

Take the numpy object, usually imported as np with the .array().
Within the (), put a list, with [] and commas between the values of the list.

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

Describe the format for splitting a numpy matrix.

A

The matrix variable will have [] behind it and those [] will hold the x and y range. The first value in the [] will be the x range, with similar principles of splitting lists in Python, i.e. x1:x2-1. The second value after a comma will be similar but for columns.

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

What are two numpy save formats?

A

.npy and .npz
in .npz, you can use the np.savez() command to save several arrays in a single uncompressed file.

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

Give an example of how to save a numpy array/matrix to a .npy file.

A

np.save(‘path’, matrix)

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