Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
91.
How can you calculate the mean of a NumPy array arr along the second axis?
arr.mean(axis=1)
np.mean(arr, axis=1)
np.mean(axis=1, arr)
arr.mean(axis=0)
Answer: Option
Explanation:
The mean() function with axis=1 calculates the mean along the second axis.

92.
What does the NumPy function numpy.unique(arr) return?
Unique elements of the array.
Count of unique elements in the array.
Sorted array with unique elements.
Index of unique elements in the array.
Answer: Option
Explanation:
The numpy.unique() function returns unique elements of the array.

93.
Given a NumPy array arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), how can you extract the diagonal elements?
arr.diagonal()
arr[1:3, 1:3]
np.diag(arr)
arr[::2, ::2]
Answer: Option
Explanation:
The np.diag() function extracts the diagonal elements of the array.

94.
How can you concatenate two NumPy arrays arr1 and arr2 vertically?
np.concatenate((arr1, arr2), axis=0)
np.vstack((arr1, arr2))
np.vertical_concatenate((arr1, arr2))
arr1 + arr2
Answer: Option
Explanation:
The np.vstack() function vertically stacks arrays.

95.
What does the NumPy function numpy.arange(1, 10, 2) generate?
[1, 3, 5, 7, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[2, 4, 6, 8, 10]
[1, 4, 7]
Answer: Option
Explanation:
The numpy.arange() function generates an array with evenly spaced values.