Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
61.
What is the result of the expression np.linspace(0, 1, 5, endpoint=False)?
[0.0, 0.2, 0.4, 0.6, 0.8]
[0.0, 0.25, 0.5, 0.75, 1.0]
[0.0, 0.1, 0.2, 0.3, 0.4]
[0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
Answer: Option
Explanation:
The expression generates an array with values from 0.0 to 1.0 (exclusive) with a step of 0.2 and excludes the endpoint.

62.
Given a NumPy array arr = np.array([[1, 2, 3], [4, 5, 6]]), what does arr.shape return?
(2, 3)
(3, 2)
(2,)
(3,)
Answer: Option
Explanation:
The arr.shape attribute returns the dimensions of the array.

63.
How can you create a NumPy array filled with zeros of shape (4, 4)?
np.zeros((4, 4))
np.ones((4, 4))
np.empty((4, 4))
np.full((4, 4), 0)
Answer: Option
Explanation:
The np.zeros() function creates an array filled with zeros of the specified shape.

64.
How do you reshape a NumPy array arr into a single-dimensional array?
arr.reshape((1, -1))
arr.flatten()
arr.reshape((-1, 1))
arr.ravel()
Answer: Option
Explanation:
The arr.ravel() function flattens the array into a single-dimensional array.

65.
What is the purpose of the NumPy function numpy.vstack((arr1, arr2))?
Stacks the arrays vertically.
Stacks the arrays horizontally.
Creates a new array by vertically concatenating the arrays.
Creates a new array by horizontally concatenating the arrays.
Answer: Option
Explanation:
The numpy.vstack() function stacks the arrays vertically.