Bird
0
0

Which dtype should you specify to create a NumPy array of boolean values?

easy📝 Conceptual Q2 of 15
NumPy - Array Data Types
Which dtype should you specify to create a NumPy array of boolean values?
A'bool'
B'int'
C'float'
D'str'
Step-by-Step Solution
Solution:
  1. Step 1: Identify dtype for boolean arrays

    NumPy uses 'bool' dtype to represent boolean True/False values.
  2. Step 2: Check other options

    'int' and 'float' are numeric types; 'str' is for text, so they are incorrect for booleans.
  3. Final Answer:

    'bool' -> Option A
  4. Quick Check:

    Boolean arrays use dtype='bool' = B [OK]
Quick Trick: Use dtype='bool' for True/False arrays [OK]
Common Mistakes:
  • Using 'int' instead of 'bool'
  • Confusing 'str' with boolean
  • Not specifying dtype at all

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes