Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
51.
How can you calculate the element-wise product of two NumPy arrays arr1 and arr2?
np.multiply(arr1, arr2)
arr1 * arr2
np.prod(arr1, arr2)
np.product(arr1, arr2)
Answer: Option
Explanation:
The element-wise product can be calculated using the multiplication operator *.

52.
What does the NumPy function numpy.random.rand(2, 3) do?
Creates a 2x3 array with all elements initialized to zero.
Generates a random array with values between 0 and 1.
Reshapes an existing array to have dimensions 2x3.
Computes the square root of each element in the array.
Answer: Option
Explanation:
The numpy.random.rand() function generates a random array with values between 0 and 1.

53.
How can you find the index of the minimum value in a NumPy array arr?
np.argmin(arr)
arr.index(min(arr))
np.minimum_index(arr)
arr.min_index()
Answer: Option
Explanation:
The np.argmin() function returns the index of the minimum value in the array.

54.
Given a NumPy array arr = np.array([3, 1, 4, 1, 5, 9]), what does np.sort(arr) return?
[1, 1, 3, 4, 5, 9]
[9, 5, 4, 3, 1, 1]
[1, 3, 1, 4, 5, 9]
[1, 1, 4, 3, 5, 9]
Answer: Option
Explanation:
The np.sort() function returns a sorted version of the array.

55.
What does the NumPy function numpy.flip(arr, axis=1) do?
Flips the array vertically.
Flips the array horizontally.
Flips the array along both axes.
Flips the array along the specified axis.
Answer: Option
Explanation:
The numpy.flip() function flips the array horizontally along the specified axis.