Unit 5: Matrices - Practice Quiz
1 Which Python module is commonly used to generate random numbers?
2
What does np.random.randint(1, 5) generate?
3 What is the main purpose of NumPy in Python?
4 Which statement correctly imports NumPy using the common alias?
5
If a = np.array([10, 20, 30]), what is the value of a[1]?
6
For a two-dimensional array A, what does A[0, 1] select?
7
What elements are selected by a[1:4] for a one-dimensional NumPy array?
8 Which NumPy array attribute gives the number of dimensions?
9
What information does the shape attribute provide?
10 Which attribute returns the total number of elements in a NumPy array?
11
If a = np.array([1, 2]) and b = np.array([3, 4]), what is a + b?
12 Which operator performs element-wise multiplication for NumPy arrays?
13 Which NumPy function calculates the sum of array elements?
14 Which function changes the shape of an array without changing its data?
15
What does np.concatenate() generally do?
16 What is the main purpose of matrix decomposition?
17 In an LU decomposition, what do the letters L and U usually represent?
18 What is a sparse matrix?
19 Which SciPy submodule provides sparse matrix structures?
20 What is SciPy mainly used for?
21 What is the main purpose of setting a seed before generating random numbers with NumPy?
22
What is the shape of the array returned by np.random.default_rng(3).uniform(size=(2, 4))?
(4, 2)
(2, 4)
(2, 4, 1)
(8,)
23
What is the result of np.array([1, 2, 3]) + np.array([4, 5, 6])?
[4, 5, 6, 1, 2, 3]
[1, 2, 3, 4, 5, 6]
[4, 10, 18]
[5, 7, 9]
24 Which expression creates a NumPy array containing zeros with floating-point data type?
np.zeros((3, 3), dtype=float)
np.zeros(3, 3, dtype=float)
np.ones((3, 3), dtype=float)
np.empty((3, 3), dtype=int)
25
Given A = np.array([[2, 4, 6], [8, 10, 12], [14, 16, 18]]), what does A[1:, :2] return?
[[4, 6], [10, 12]]
[[8, 10], [14, 16]]
[[2, 4], [8, 10]]
[[8, 10, 12], [14, 16, 18]]
26
For A = np.arange(12).reshape(3, 4), which expression selects the last column as a one-dimensional array?
A[-1, -1]
A[-1, :]
A[:, :-1]
A[:, -1]
27
If A = np.zeros((2, 3, 4), dtype=np.int32), what are A.ndim and A.size?
ndim is 2 and size is 24
ndim is 3 and size is 9
ndim is 3 and size is 24
ndim is 4 and size is 24
28
An array has shape == (5, 2) and dtype == np.float64. Which statement about A.itemsize is correct?
29
Given A = np.array([[1, 2], [3, 4]]), what is the result of A @ A?
[[2, 4], [6, 8]]
[[7, 10], [15, 22]]
[[1, 4], [9, 16]]
[[5, 5], [5, 5]]
30
For A = np.array([[1, 2], [3, 4]]), what is the result of A * 2 + 1?
[[2, 4], [6, 8]]
[[3, 5], [7, 9]]
[[3, 4], [5, 6]]
[[4, 6], [8, 10]]
31
What does np.sum(A, axis=0) calculate for a two-dimensional array A?
32
What is the shape of np.arange(12).reshape(4, 3).T?
(4, 3)
(1, 12)
(12, 1)
(3, 4)
33
If a = np.array([1, 2]) and b = np.array([3, 4]), which expression produces [[1, 2], [3, 4]]?
np.column_stack((a, b))
np.vstack((a, b))
np.hstack((a, b))
np.concatenate((a, b), axis=1)
34
What is the effect of np.where(A > 5, A, 0) on an array A?
35 For a square matrix , which equation describes an LU decomposition when is included for pivoting?
36 Which decomposition is most directly associated with expressing a matrix as , where has orthonormal columns?
37 Which sparse matrix format is generally efficient for matrix-vector multiplication and row slicing?
38 A sparse matrix has shape and only 200 nonzero values. What is a key advantage of storing it in a sparse format?
39 Which SciPy function is appropriate for solving a square linear system ?
scipy.linalg.det(A, b)
scipy.linalg.inv(b, A)
scipy.linalg.solve(A, b)
scipy.linalg.eig(A, b)
40
Which vectorized expression returns the squares of all elements in a NumPy array x without an explicit Python loop?
x @ x
x ** 2
x // 2
x ^ 2
41
Given rng = np.random.default_rng(123), which statement best explains why calling rng.integers(0, 10, 5) twice generally produces different arrays, while creating a new np.random.default_rng(123) before each call produces identical arrays?
42
What is the shape of the result of rng.normal(size=(2, 1, 3)) + rng.normal(size=(1, 4, 1)), assuming both calls use the same Generator but independent draws?
(2, 4, 3)
(2, 1, 3)
(1, 4, 3)
43
Let a = np.array([[1, 2], [3, 4]]) and b = np.array([[5, 6], [7, 8]]). Which expression produces the matrix product rather than elementwise multiplication?
np.multiply(a, b)
np.broadcast_to(a, b.shape)
a * b
a @ b
44
What is the dtype of np.array([1, 2], dtype=np.int8) + np.array([300], dtype=np.int16) on standard NumPy type-promotion rules?
float64
int16
int8
int32
45
Consider a = np.arange(12).reshape(3, 4). Which statement is correct about x = a[:, 1:3] and y = a[:, [1, 2]]?
a.
a.
x is an advanced-indexing copy, whereas y is usually a view.
x is usually a view, whereas y is an advanced-indexing copy.
46
For a = np.arange(20).reshape(4, 5), what is the shape of a[[0, 2], 1:4]?
(2, 4)
(4, 3)
(3, 2)
(2, 3)
47
Given a = np.array([10, 20, 30, 40]) and idx = np.array([1, 1, 3]), what is the result of a[idx] += 5?
[10, 25, 30, 50]
[10, 30, 30, 45]
[10, 20, 30, 45]
[10, 25, 30, 45]
48
For a = np.arange(24, dtype=np.float64).reshape(2, 3, 4), which tuple gives (a.ndim, a.shape, a.size, a.itemsize)?
(3, (2, 3, 4), 24, 64)
(3, (2, 3, 4), 24, 8)
(2, (3, 4), 24, 8)
(3, (2, 3, 4), 48, 8)
49
For a C-contiguous array a = np.arange(12).reshape(3, 4), what is the expected value of a.strides on a platform where an integer occupies 8 bytes?
(32, 8)
(24, 8)
(32, 4)
(8, 32)
50
For x = np.array([1.0, 2.0, 4.0]), which expression computes the Euclidean norm without explicitly forming x @ x?
np.sqrt(np.sum(x ** 2))
np.sqrt(np.sum(x) ** 2)
np.sum(x ** 0.5) ** 2
np.sum(np.sqrt(x ** 2))
51
Let A have shape (3, 4) and b have shape (4,). Which expression subtracts the column vector represented by b from every row of A using broadcasting?
A - b
A - b[None, :]
A - A.T @ b
A - b[:, None]
52
For a numerically stable computation of log(exp(x).sum()) when x may contain very large values, which expression is preferred?
scipy.special.logsumexp(x)
np.log(np.exp(x).sum())
np.exp(np.log(x).sum())
np.log10(np.exp(x).sum())
53
Let a = np.arange(6). What is the key difference between a.reshape(2, 3) and np.resize(a, (2, 4))?
reshape changes dtype; resize preserves the original dtype.
reshape sorts values; resize preserves only unique values.
reshape requires the same element count; resize may repeat or truncate data.
reshape always copies; resize always returns a view.
54
For a = np.array([[1, 2], [3, 4]]), what is the shape of np.concatenate([a, a], axis=0) compared with np.concatenate([a, a], axis=1)?
(2, 4) and (4, 2)
(2, 2) and (2, 2)
(4, 4) and (4, 4)
(4, 2) and (2, 4)
55
Which operation converts a two-dimensional array A into a one-dimensional view when the memory layout permits it, without changing the element order?
A.transpose()
A.flatten()
A.squeeze(axis=0)
A.ravel()
56 If an matrix has singular values , which truncated SVD gives the best rank- approximation in the Frobenius norm?
U[:, :k] @ np.diag(s[:k]) @ Vt[:k, :]
U[:, k:] @ np.diag(s[k:]) @ Vt[k:, :]
U[:k, :] @ np.diag(s[:k]) @ Vt[:, :k]
U @ np.diag(s) @ Vt[:k, :]
57
For a nonsingular matrix , which SciPy operation is generally preferable to explicitly computing np.linalg.inv(A) when solving ?
np.linalg.eig(A) @ b
scipy.linalg.det(A) * b
scipy.linalg.solve(A, b)
scipy.linalg.norm(A) @ b
58
A COO sparse matrix is constructed with row indices [0, 0], column indices [1, 1], and data [2, 3]. After conversion to CSR format, what value is stored at position (0, 1) under standard duplicate-handling behavior?
2
3
5
59 Which sparse format is usually most suitable for efficient row slicing and matrix-vector multiplication after construction?
60 For a symmetric positive-definite matrix , which factorization is most appropriate and commonly more efficient than a general LU factorization?
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →