Recall & Review
beginner
What is boolean masking in numpy?
Boolean masking is a way to select elements from an array using a condition that returns True or False for each element. It helps filter data easily.
Click to reveal answer
beginner
Why is boolean masking useful in data analysis?
It allows quick filtering of data without loops, making code simpler and faster. You can pick only the data you need based on conditions.
Click to reveal answer
intermediate
How does boolean masking improve performance compared to loops?
Boolean masking uses numpy's optimized operations that run in compiled code, which is much faster than Python loops over large data.
Click to reveal answer
beginner
Give a simple example of boolean masking in numpy.
If you have an array of numbers, you can select only those greater than 5 by writing: arr[arr > 5]. This returns a new array with only numbers bigger than 5.
Click to reveal answer
intermediate
What happens if you use boolean masking with multiple conditions?
You can combine conditions with & (and) or | (or) inside parentheses to filter data with complex rules, like arr[(arr > 5) & (arr < 10)].
Click to reveal answer
What does boolean masking return when applied to a numpy array?
✗ Incorrect
Boolean masking returns a new array containing only elements where the mask is True.
Which operator is used to combine multiple conditions in boolean masking?
✗ Incorrect
In numpy boolean masking, & is used for 'and' and | for 'or' between conditions.
Why is boolean masking faster than using a for-loop to filter data?
✗ Incorrect
Numpy uses compiled code for operations, making boolean masking faster than Python loops.
What will arr[arr > 10] do if arr is a numpy array?
✗ Incorrect
This expression returns a new array with elements from arr that are greater than 10.
If you want to select elements between 5 and 15 in an array, which is correct?
✗ Incorrect
You must use & with parentheses to combine conditions in numpy boolean masking.
Explain in your own words why boolean masking is important when working with numpy arrays.
Think about how you pick certain items from a list based on a rule.
You got /4 concepts.
Describe how you would use boolean masking to find all numbers greater than 10 and less than 20 in a numpy array.
Remember to use & and parentheses for multiple conditions.
You got /3 concepts.