Bird
0
0

Find the bug in this code:

medium📝 Debug Q7 of 15
NumPy - Array Data Types
Find the bug in this code:
import numpy as np
arr = np.array([True, False, True])
print(arr & [False, True, False])
ACannot use & between numpy array and list directly
BNo bug, code runs correctly
CBoolean arrays cannot use & operator
DList should be converted to numpy array first
Step-by-Step Solution
Solution:
  1. Step 1: Understand operator & between numpy array and list

    Numpy's & operator automatically converts Python lists to arrays for element-wise operations.
  2. Step 2: Verify the code runs

    The code executes without error, producing [False True False].
  3. Final Answer:

    No bug, code runs correctly -> Option B
  4. Quick Check:

    & coerces list to array automatically [OK]
Quick Trick: Numpy & operator works directly with lists [OK]
Common Mistakes:
  • Thinking & requires both arrays explicitly
  • Expecting TypeError with list operand
  • Confusing with Python 'and' keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes