1/32
Looks like no tags are added yet.
How do you create a NumPy array of [2,4,6]?
np.array([2, 4, 6])
How do you make 5 zeros?
np.zeros(5)
How do you make 4 ones?
np.ones(4)
What does x.size tell you?
The total number of elements in the array.
What does x.shape tell you?
The dimensions of the array, e.g. (4,) or (3,2)
What does x.ndim tell you?
The number of array dimensions
What does np.abs(x) do to a NumPy array?
Takes absolute value of each element
How do you discard zeros and take absolute values?
np.abs(x[x != 0])
What does x*3 do for a NumPy array?
Multiplies every element by 3
What does x**2 do for a NumPy array?
Squares every element separately
How does x+y work for same-shaped NumPy arrays?
Adds corresponding elements (elementwise)
What is the safest pattern for an independent array copy?
y = x.copy()
Why can y=x be risky for a NumPy array?
Both names refer to the same array; editing it through either name affects both
What does a NumPy array let one variable store?
Multiple values, often numbers, in a single array object
Make the NumPy array [1, -2, 3]
x = np.array([1, -2, 3])
What does np.zeros(3) produce?
[0. 0. 0.] (three zero values)
What does np.ones(2)*5 produce?
[5. 5.]
If x=np.array([2,4,6]), what is x+3?
[5 7 9]; 3 is added to every element
If x=np.array([2,4,6]), what is 2*x?
[4 8 12]
If x=np.array([2,4,6]), what is x**2?
[4 16 36]
For x=[1,2,3], y=[4,5,6] as NumPy arrays, what is x+y?
[5 7 9]
For NumPy x=[1,2], y=[3,4], what is x*y?
[3 8]; ordinary * multiplies corresponding entries
Does * between same-shaped NumPy arrays normally mean matrix
multiplication?
No. It is elementwise multiplication.
If x has 5 elements, what is x.shape?
(5,), a one-entry tuple describing the 1-D shape
If A has 3 rows and 4 columns, what is A.size?
12 (total entries)
If A is a 3x4 array, what is A.ndim?
2
How do you check the data type of variable x?
type(x)
What does x=np.array([-3,0,4]); np.abs(x) return?
[3 0 4]
What does a=4; b=a; a=9; print(b) output?
4; ordinary numeric assignment does not link values like arrays
What changes when you use b=a.copy() instead of b=a for arrays?
b becomes an independent array; edits to a do not modify b
What happens when adding NumPy arrays of incompatible shapes?
Usually a ValueError unless NumPy broadcasting rules allow them
What NumPy command creates 6 zeros ready to fill in a loop?
values = np.zeros(6)
For x=np.array([1,2,3]), what is x/2?
[0.5 1. 1.5]