Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
86.
What does the NumPy function numpy.identity(3) generate?
3x3 array with ones on the main diagonal.
3x3 array with ones above the main diagonal.
3x3 array with ones below the main diagonal.
3x3 array with zeros on the main diagonal.
Answer: Option
Explanation:
The numpy.identity() function generates an identity matrix with ones on the main diagonal.

87.
How can you flatten a NumPy array arr in column-major order?
arr.flatten()
np.column_stack(arr)
arr.ravel(order='F')
np.column_major(arr)
Answer: Option
Explanation:
The ravel() function with order='F' flattens the array in column-major order.

88.
Given a NumPy array arr = np.array([10, 20, 30, 40]), what does arr[1:3] return?
[10, 20]
[20, 30]
[30, 40]
[20, 30, 40]
Answer: Option
Explanation:
The slice arr[1:3] extracts elements from index 1 to (3-1).

89.
How can you reshape a NumPy array arr to have 2 rows and 3 columns?
np.reshape(arr, (2, 3))
arr.resize(2, 3)
arr.reshape(2, 3)
np.resize(arr, (2, 3))
Answer: Option
Explanation:
The reshape() function is used to reshape the array.

90.
What is the result of the expression np.linspace(0, 1, num=5, endpoint=False)?
[0.0, 0.25, 0.5, 0.75, 1.0]
[0.0, 0.2, 0.4, 0.6, 0.8]
[0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
[0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2]
Answer: Option
Explanation:
The np.linspace() function generates evenly spaced numbers over a specified range.