Which NumPy function is used to create an array of a specified shape where all…
2026
Which NumPy function is used to create an array of a specified shape where all elements are initialized to the value 0?
- A.
np.empty()
- B.
np.zeros()
- C.
np.ones()
- D.
np.null()
Attempted by 99 students.
Show answer & explanation
Correct answer: B
The correct function is np.zeros(). This NumPy function creates an array of a specified shape where all elements are initialized to 0. Other functions like np.ones() initialize to 1, np.empty() leaves data uninitialized, and np.null() is not a valid function.