Exercise: Python

Questions for: Arrays

Given two NumPy arrays arr1 and arr2, what does np.vstack((arr1, arr2)) do?
A:
Stacks the arrays vertically.
B:
Stacks the arrays horizontally.
C:
Creates a new array by vertically concatenating the arrays.
D:
Creates a new array by horizontally concatenating the arrays.
Answer: A
The np.vstack() function stacks the arrays vertically.
How can you find the mean value along a specific axis in a NumPy array arr?
A:
np.mean(arr, axis=1)
B:
np.average(arr, axis=0)
C:
arr.calculate_mean(axis=1)
D:
arr.mean(axis=0)
Answer: A
The np.mean() function can compute the mean along a specified axis.
What does the NumPy function numpy.eye(3) do?
A:
Creates a 3x3 array with random values.
B:
Generates an identity matrix of size 3x3.
C:
Computes the eigenvalues of a 3x3 matrix.
D:
Reshapes an existing array to have dimensions 3x3.
Answer: B
The numpy.eye() function generates an identity matrix of the specified size.
What is the purpose of the NumPy function numpy.argmax(arr)?
A:
Finds the minimum value in the array.
B:
Returns the index of the maximum value in the array.
C:
Computes the average value of the array.
D:
Reshapes the array to have a specified number of dimensions.
Answer: B
The numpy.argmax() function returns the index of the maximum value in the array.
Given a NumPy array arr = np.array([2, 4, 6, 8, 10]), how do you extract elements at even indices?
A:
arr[::2]
B:
arr[1::2]
C:
arr[1:][::2]
D:
arr[1::]
Answer: A
The code arr[::2] extracts elements at even indices from the array.
Ad Slot (Above Pagination)
Quiz