Question bank

Pick an answer to see if you're right — with an explanation.

NumPyEasy
How many bytes does one `float32` value use?
a2
b4
c8
d16
NumPyEasy
Which is the recommended way to create random numbers in modern NumPy?
arng = np.random.default_rng(42)
bnp.random.seed(42); np.random.rand()
cimport random; random.random()
dnp.rand(42)
NumPyEasy
Which operator performs matrix multiplication of two NumPy arrays?
a*
b**
c@
d//
NumPyEasy
What is the shape of `np.arange(12).reshape(3, -1)`?
a(3, 3)
b(12, 3)
c(3, 12)
d(3, 4)
NumPyMedium
What does this print?
a = np.array([[1, 2, 3],
              [4, 5, 6]])
print(a.sum(axis=0))
a[6 15]
b[5 7 9]
c21
d[[5 7 9]]
NumPyMedium
What is the difference between `np.stack([a, b])` and `np.concatenate([a, b])` for two 1-D arrays of length 3?
astack gives shape (2, 3); concatenate gives shape (6,)
bBoth give shape (6,)
cstack gives shape (6,); concatenate gives (2, 3)
dBoth give shape (2, 3)
NumPyMedium
Why is `np.linalg.solve(A, b)` preferred over `np.linalg.inv(A) @ b`?
ainv() only works on integer matrices
bsolve() also returns eigenvalues
csolve() works on non-square matrices
dsolve() is faster and more numerically accurate
NumPyMedium
To divide each row of `m` (shape (3, 4)) by its row total, which expression is correct?
am / m.sum(axis=0)
bm / m.sum()
cm / m.sum(axis=1, keepdims=True)
dm / m.sum(axis=1)
NumPyHard
What does this code print?
x = np.array([100, 120], dtype=np.int8)
print(x + x)
a[200 240]
b[-56 -16]
cOverflowError is raised
d[127 127]
NumPyHard
After `v = a.reshape(2, 6)` on a contiguous 12-element array `a`, you run `v[0, 0] = 99`. What happens to `a[0]`?
aIt stays unchanged because reshape copies
bIt raises an error because views are read-only
cIt becomes NaN
dIt also becomes 99 because v is a view sharing memory