Exercise: Python

Questions for: Arrays

Given two NumPy arrays arr1 = np.array([1, 2, 3]) and arr2 = np.array([4, 5, 6]), what does np.dot(arr1, arr2) return?
A:
64
B:
[4, 10, 18]
C:
[1, 2, 3, 4, 5, 6]
D:
32
Answer: D
The np.dot() function calculates the dot product of two arrays.
How can you find the mean of a NumPy array arr?
A:
np.mean(arr)
B:
arr.calculate_mean()
C:
np.average(arr)
D:
arr.mean()
Answer: A
The np.mean() function calculates the mean of the array.
What does the NumPy function numpy.arange(1, 10, 2) return?
A:
[1, 3, 5, 7, 9]
B:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
C:
[2, 4, 6, 8]
D:
[1, 4, 7, 10]
Answer: A
The numpy.arange() function creates an array with values from start (inclusive) to stop (exclusive) with the specified step.
How can you calculate the sum of all elements in a NumPy array arr?
A:
arr.sum()
B:
np.add(arr)
C:
np.sum(arr)
D:
arr.calculate_sum()
Answer: C
The np.sum() function calculates the sum of all elements in the array.
What is the purpose of the NumPy function numpy.vstack((arr1, arr2))?
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 numpy.vstack() function stacks the arrays vertically.
Ad Slot (Above Pagination)
Quiz