Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
66.
How can you calculate the sum of all elements in a NumPy array arr?
arr.sum()
np.add(arr)
np.sum(arr)
arr.calculate_sum()
Answer: Option
Explanation:
The np.sum() function calculates the sum of all elements in the array.

67.
What does the NumPy function numpy.arange(1, 10, 2) return?
[1, 3, 5, 7, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[2, 4, 6, 8]
[1, 4, 7, 10]
Answer: Option
Explanation:
The numpy.arange() function creates an array with values from start (inclusive) to stop (exclusive) with the specified step.

68.
How can you find the mean of a NumPy array arr?
np.mean(arr)
arr.calculate_mean()
np.average(arr)
arr.mean()
Answer: Option
Explanation:
The np.mean() function calculates the mean of the array.

69.
Given two NumPy arrays arr1 = np.array([1, 2, 3]) and arr2 = np.array([4, 5, 6]), what does np.dot(arr1, arr2) return?
64
[4, 10, 18]
[1, 2, 3, 4, 5, 6]
32
Answer: Option
Explanation:
The np.dot() function calculates the dot product of two arrays.

70.
What is the purpose of the NumPy function numpy.identity(3)?
Creates a 3x3 array with all elements initialized to zero.
Generates the identity matrix of order 3.
Reshapes an existing array to have dimensions 3x3.
Computes the inverse of a 3x3 matrix.
Answer: Option
Explanation:
The numpy.identity() function creates the identity matrix of the specified order.