Recall & Review
beginner
What does the
numpy.logical_and() function do?It performs an element-wise logical AND operation between two arrays, returning
True only where both elements are True.Click to reveal answer
beginner
How does
numpy.logical_or() differ from numpy.logical_and()?numpy.logical_or() returns True if at least one element in the pair is True, unlike logical_and() which requires both to be True.Click to reveal answer
beginner
What is the purpose of
numpy.logical_not()?It returns the element-wise logical NOT of an array, flipping
True to False and vice versa.Click to reveal answer
intermediate
Why use
numpy.logical_and() instead of Python's and with arrays?Python's
and does not work element-wise on arrays. numpy.logical_and() applies the operation to each pair of elements, which is needed for array data.Click to reveal answer
intermediate
How can you combine multiple logical operations in NumPy?
You can nest
numpy.logical_and(), numpy.logical_or(), and numpy.logical_not() calls to create complex conditions applied element-wise.Click to reveal answer
What will
numpy.logical_and([True, False], [True, True]) return?✗ Incorrect
Element-wise AND: True AND True is True; False AND True is False.
Which function flips True to False and False to True in NumPy?
✗ Incorrect
numpy.logical_not() performs element-wise logical NOT.What does
numpy.logical_or([False, False], [True, False]) return?✗ Incorrect
Element-wise OR: False OR True is True; False OR False is False.
Why can't you use Python's
and directly on NumPy arrays?✗ Incorrect
Python's
and expects single boolean values, not arrays, so it raises an error.How do you combine
logical_and and logical_not in NumPy?✗ Incorrect
You can nest logical functions like
numpy.logical_and(a, numpy.logical_not(b)) for combined conditions.Explain how to perform element-wise logical AND, OR, and NOT operations on NumPy arrays.
Think about how to check conditions for each item in a list.
You got /4 concepts.
Describe why Python's built-in logical operators cannot be used directly on NumPy arrays and how NumPy solves this.
Consider how Python handles single values vs lists.
You got /4 concepts.