Bird
0
0

You want to create a zero-filled 2D array with 3 rows and 4 columns, but the array must store boolean values. Which code is correct?

hard📝 Application Q15 of 15
NumPy - Creating Arrays
You want to create a zero-filled 2D array with 3 rows and 4 columns, but the array must store boolean values. Which code is correct?
Anp.zeros((3,4), type=bool)
Bnp.zeros(3,4, dtype=bool)
Cnp.zeros([3,4], dtype=bool)
Dnp.zeros((3,4), dtype=bool)
Step-by-Step Solution
Solution:
  1. Step 1: Check shape argument format

    The shape must be a tuple, so (3,4) is correct.
  2. Step 2: Verify dtype argument name and value

    The correct keyword is dtype, and bool is valid to create boolean arrays.
  3. Step 3: Eliminate incorrect options

    Using the wrong keyword type instead of dtype, passing shape as separate arguments like np.zeros(3,4, dtype=bool) without tuple parentheses, using a list [3,4] instead of tuple.
  4. Final Answer:

    np.zeros((3,4), dtype=bool) -> Option D
  5. Quick Check:

    Shape tuple and dtype=bool required [OK]
Quick Trick: Use tuple for shape and dtype=bool for boolean zeros [OK]
Common Mistakes:
  • Passing shape as separate args
  • Using list instead of tuple
  • Wrong keyword 'type' instead of 'dtype'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes