Recall & Review
beginner
What does a boolean array represent in numpy?
A boolean array in numpy contains True or False values, often used to mark conditions or filters on data.
Click to reveal answer
beginner
How can you count the number of True values in a numpy boolean array?
You can use the
np.sum() function on the boolean array because True is treated as 1 and False as 0.Click to reveal answer
intermediate
Why does
np.sum() work for counting True values in a boolean array?Because in numpy, True is equivalent to 1 and False is equivalent to 0, so summing counts how many True values exist.
Click to reveal answer
intermediate
What is the difference between
np.count_nonzero() and np.sum() when used on boolean arrays?np.count_nonzero() counts all non-zero (True) elements, similar to np.sum() on boolean arrays. Both give the count of True values.Click to reveal answer
beginner
How can boolean arrays help in real-life data analysis?
Boolean arrays help filter data, count conditions met, and quickly summarize information like how many entries meet a rule.
Click to reveal answer
What does
np.sum() return when applied to a boolean numpy array?✗ Incorrect
np.sum() treats True as 1 and False as 0, so it returns the count of True values.Which numpy function can also count True values in a boolean array besides
np.sum()?✗ Incorrect
np.count_nonzero() counts all non-zero (True) elements in the array.In numpy, what numeric value does False correspond to when used in calculations?
✗ Incorrect
False is treated as 0 in numpy numeric operations.
If you have a boolean array
[True, False, True], what does np.sum() return?✗ Incorrect
There are two True values, so the sum is 2.
Why are boolean arrays useful in data science?
✗ Incorrect
Boolean arrays let you quickly find and count data entries that meet specific conditions.
Explain how you can count how many values in a numpy array meet a certain condition using boolean arrays.
Think about how True and False behave as numbers in numpy.
You got /3 concepts.
Describe two numpy functions that can count True values in a boolean array and how they work.
Both functions treat True as a positive count.
You got /4 concepts.