Bird
0
0

Why does np.ones((3, 3), dtype=bool) create an array of True values instead of numeric ones?

hard📝 Conceptual Q10 of 15
NumPy - Creating Arrays
Why does np.ones((3, 3), dtype=bool) create an array of True values instead of numeric ones?
ABecause dtype=bool converts all values to False
BBecause in boolean type, 1 is interpreted as True
CBecause np.ones() always returns boolean arrays
DBecause np.ones() ignores dtype argument
Step-by-Step Solution
Solution:
  1. Step 1: Understand dtype=bool effect

    When dtype is boolean, numeric 1 converts to True, and 0 converts to False.
  2. Step 2: Explain np.ones() behavior

    np.ones() creates numeric ones, but dtype=bool converts these to True values.
  3. Final Answer:

    Because in boolean type, 1 is interpreted as True -> Option B
  4. Quick Check:

    Boolean dtype converts 1 to True [OK]
Quick Trick: Boolean dtype converts numeric 1 to True automatically [OK]
Common Mistakes:
  • Thinking np.ones() always returns numeric arrays
  • Assuming dtype=bool creates False values
  • Ignoring dtype argument effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes