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?

  1. A.

    np.empty()

  2. B.

    np.zeros()

  3. C.

    np.ones()

  4. 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.

Explore the full course: Bpsc