Exercise: Python

Questions for: Arrays

What is the purpose of the NumPy function numpy.flip(arr, axis=1)?
A:
Flips the array vertically.
B:
Flips the array horizontally.
C:
Flips the array along both axes.
D:
Transposes the array.
Answer: B
The numpy.flip() function flips the array horizontally along the specified axis.
Given a NumPy array arr = np.array([[1, 2, 3], [4, 5, 6]]), how can you access the element 5?
A:
arr[1, 2]
B:
arr[1, 1]
C:
arr[0, 2]
D:
arr[1, 0]
Answer: B
The indexing starts from 0, so arr[1, 2] refers to the element in the second row and second column.
How can you find the maximum value along a specific axis in a NumPy array arr?
A:
np.max(arr)
B:
arr.maximum(axis=0)
C:
np.maximum(arr, axis=0)
D:
np.max(arr, axis=0)
Answer: D
The np.max() function can be used with the axis parameter to find the maximum value along a specific axis.
What does the NumPy function numpy.random.randint(1, 100, size=(3, 3)) do?
A:
Generates a random integer between 1 and 100.
B:
Creates a 3x3 array with random integers between 1 and 100.
C:
Reshapes an existing array to have dimensions 3x3.
D:
Computes the mean of random integers between 1 and 100.
Answer: B
The numpy.random.randint() function creates a random integer array of the specified size.
What is the purpose of the NumPy function numpy.identity(3)?
A:
Creates a 3x3 array with all elements initialized to zero.
B:
Generates the identity matrix of order 3.
C:
Reshapes an existing array to have dimensions 3x3.
D:
Computes the inverse of a 3x3 matrix.
Answer: B
The numpy.identity() function creates the identity matrix of the specified order.
Ad Slot (Above Pagination)
Quiz