Bird
0
0

Given two boolean arrays:

hard📝 Application Q9 of 15
NumPy - Array Operations
Given two boolean arrays:
a = np.array([True, False, True])
b = np.array([False, True, False])

How can you create a new array that is True only if both a and b are not True at the same time (i.e., NOT (a AND b))?
Anp.logical_xor(a, b)
Bnp.logical_and(np.logical_not(a), np.logical_not(b))
Cnp.logical_not(np.logical_and(a, b))
Dnp.logical_or(a, b)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the expression NOT (a AND b)

    This means the result is True when a and b are not both True simultaneously.
  2. Step 2: Use NumPy functions to express it

    First compute np.logical_and(a, b), then negate with np.logical_not.
  3. Final Answer:

    np.logical_not(np.logical_and(a, b)) -> Option C
  4. Quick Check:

    NOT (a AND b) = np.logical_not(np.logical_and(a, b)) [OK]
Quick Trick: Combine logical_and and logical_not for NOT (a AND b) [OK]
Common Mistakes:
  • Using De Morgan's incorrectly
  • Confusing with XOR
  • Using OR instead of AND inside NOT

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes