Bird
0
0

Which of the following converts an array of integers to a boolean array where zero becomes False and non-zero becomes True?

easy📝 Conceptual Q2 of 15
NumPy - Array Data Types
Which of the following converts an array of integers to a boolean array where zero becomes False and non-zero becomes True?
Anp.bool_()
Barr.astype(bool)
Cnp.to_bool()
Dnp.boolarray()
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct numpy method for type conversion

    The method to convert array types is astype().
  2. Step 2: Apply astype(bool) to convert integers to boolean

    Using astype(bool) converts zeros to False and non-zeros to True.
  3. Final Answer:

    arr.astype(bool) -> Option B
  4. Quick Check:

    Conversion method = astype(bool) [OK]
Quick Trick: Use astype(bool) to convert numeric arrays to boolean [OK]
Common Mistakes:
  • Using non-existent np.to_bool()
  • Trying np.bool_() as a function
  • Confusing with np.boolarray() which doesn't exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes