Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
NumPy - Creating Arrays
What is the output of the following code?
import numpy as np
arr = np.zeros(4, dtype=int)
print(arr)
A[0 0 0 0]
B[0. 0. 0. 0.]
C[1 1 1 1]
D[False False False False]
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.zeros(4, dtype=int)

    This creates a 1D array of length 4 filled with zeros, with integer type.
  2. Step 2: Check the printed output format

    Since dtype is int, zeros are printed as integers without decimal points.
  3. Final Answer:

    [0 0 0 0] -> Option A
  4. Quick Check:

    Integer zeros printed without decimals [OK]
Quick Trick: dtype=int means zeros print as integers [OK]
Common Mistakes:
  • Expecting float zeros with decimals
  • Confusing with ones array
  • Thinking output is boolean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes