CARVIEW |
Advanced NumPy
This quiz includes 10 questions, starting with intermediate-level advanced concepts and progressing to highly advanced NumPy topics. Each question has the correct answer and a detailed justification.
Question 1
What does the np.broadcast_to() function do?
Replicates a scalar value into an array
Broadcasts an array to a new shape without copying data
Concatenates two arrays along an axis
Transposes an array
Question 2
Which function is used to calculate the QR decomposition of a matrix in NumPy?
np.linalg.svd()
np.linalg.qr()
np.linalg.eig()
np.linalg.solve()
Question 3
What will be the output of this code?
import numpy as np
arr = np.array([[1, 2], [3, 4]])
result = np.kron(arr, np.eye(2))
print(result)
[[1. 0. 2. 0.]
[0. 1. 0. 2.]
[3. 0. 4. 0.]
[0. 3. 0. 4.]]
[[1. 2.]
[3. 4.]]
[[1. 0.]
[0. 2.]
[3. 0.]
[0. 4.]]
[[1. 0. 2. 0.]
[0. 1. 0. 2.]
[3. 0. 4. 0.]
[0. 3. 0. 4.]]
Question 4
Which function computes the eigenvalues and eigenvectors of a matrix?
np.linalg.det()
np.linalg.inv()
np.linalg.eig()
np.linalg.qr()
Question 5
What does the np.pad() function do in NumPy?
Creates a zero-padded array
Adds padding to an array along specified dimensions
Aligns two arrays for concatenation
Splits an array into blocks
Question 6
What will be the output of this code?
import numpy as np
arr = np.array([[1, 2], [3, 4]])
result = np.linalg.svd(arr)
print([x.shape for x in result])
[(2, 2), (2,), (2, 2)]
[(2, 2), (1,), (2, 2)]
[(2, 2), (2,), (2, 1)]
Error
Question 7
What does the np.ma.masked_array() function do?
Masks an array based on a condition
Combines two arrays
Creates a Boolean mask of an array
Reshapes an array
Question 8
Which of the following is not a valid use of np.random.Generator?
Generating random numbers with a specified seed
Generating samples from a normal distribution
Generating pseudorandom numbers for cryptography
Generating random integers
Question 9
What does the np.unique() function return when return_counts=True is specified?
Unique elements only
A tuple of unique elements and their counts
The first occurrence of each unique element
An Error
Question 10
Which function in NumPy is used to calculate the Frobenius norm of a matrix?
np.linalg.norm()
np.linalg.det()
np.linalg.inv()
np.linalg.qr()
There are 10 questions to complete.