Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Creating Arrays
What will be the output of this code?
import numpy as np
arr = np.ones(4, dtype=bool)
print(arr)
A[False False False False]
B[1 1 1 1]
C[True True True True]
D[0 0 0 0]
Step-by-Step Solution
Solution:
  1. Step 1: Understand dtype=bool in np.ones()

    np.ones() creates an array of ones, and with dtype=bool, ones convert to True.
  2. Step 2: Check the printed output

    The array will have 4 elements, all True boolean values.
  3. Final Answer:

    [True True True True] -> Option C
  4. Quick Check:

    np.ones() with bool dtype = True values [OK]
Quick Trick: Ones become True when dtype=bool is used [OK]
Common Mistakes:
  • Expecting numeric 1 instead of True
  • Confusing False with True
  • Misunderstanding dtype effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes