Recall & Review
beginner Click to reveal answer
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.beginner Click to reveal answer
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.beginner Click to reveal answer
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.intermediate Click to reveal answer
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.intermediate Click to reveal answer
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.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.
