Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a boolean array in numpy?
A boolean array in numpy is an array where each element is either True or False. It is often used for filtering or masking data.
Click to reveal answer
beginner
How do you create a boolean array from a numpy array based on a condition?
You apply a condition directly to a numpy array, which returns a boolean array. For example, arr > 5 returns True for elements greater than 5 and False otherwise.
Click to reveal answer
beginner
What numpy function can create a boolean array filled with True or False?
You can use numpy.ones(shape, dtype=bool) to create a boolean array filled with True, or numpy.zeros(shape, dtype=bool) to create one filled with False.
Click to reveal answer
beginner
How can boolean arrays help in real-life data filtering?
Boolean arrays let you select or ignore data easily. For example, in a list of temperatures, you can create a boolean array to find all days hotter than 30°C and then extract those days' data.
Click to reveal answer
beginner
What does the expression arr % 2 == 0 return when applied to a numpy array?
It returns a boolean array where each element is True if the corresponding element in arr is even, and False if it is odd.
Click to reveal answer
What type of values does a numpy boolean array contain?
AIntegers
BTrue or False
CStrings
DFloats
✗ Incorrect
Boolean arrays contain only True or False values.
Which numpy function creates a boolean array filled with False?
Anumpy.zeros(shape, dtype=bool)
Bnumpy.ones(shape, dtype=bool)
Cnumpy.empty(shape, dtype=bool)
Dnumpy.full(shape, True)
✗ Incorrect
numpy.zeros(shape, dtype=bool) creates a boolean array filled with False.
What does the expression arr > 10 return?
AA boolean array where elements are True if > 10
BAn array of numbers greater than 10
CA sum of elements greater than 10
DAn error
✗ Incorrect
Applying a condition returns a boolean array indicating which elements satisfy it.
How can boolean arrays be used in data filtering?
ATo change data types
BTo create new columns
CTo select elements that meet a condition
DTo sort data
✗ Incorrect
Boolean arrays help select elements that meet specific conditions.
What is the dtype of a boolean numpy array?
Aint
Bfloat
Cstr
Dbool
✗ Incorrect
Boolean arrays have dtype 'bool' in numpy.
Explain how to create a boolean array from a numpy array using a condition. Give a simple example.
Think about how you check if numbers are bigger than a value.
You got /3 concepts.
Describe two ways to create boolean arrays in numpy and when you might use each.
One way uses existing data, the other creates new arrays filled with True or False.
You got /3 concepts.
Practice
(1/5)
1. What does a boolean array in numpy represent?
easy
A. An array of integers only
B. An array of True/False values based on a condition
C. An array of strings
D. An array with only zeros
Solution
Step 1: Understand boolean arrays
A boolean array stores True or False for each element, usually from a condition.
Step 2: Identify the correct description
The description 'An array of True/False values based on a condition' matches what a boolean array represents. Others refer to integers, strings, or zeros.
Final Answer:
An array of True/False values based on a condition -> Option B
Quick Check:
Boolean array = True/False values [OK]
Hint: Boolean arrays always hold True or False values [OK]
Common Mistakes:
Thinking boolean arrays hold numbers or strings
Confusing boolean arrays with integer arrays
2. Which of the following is the correct way to create a boolean array from a numpy array arr to check where elements are greater than 5?
easy
A. bool_arr = arr > 5
B. bool_arr = arr == 5
C. bool_arr = arr >= 5
D. bool_arr = arr < 5
Solution
Step 1: Understand the condition for boolean array
We want True where elements are greater than 5, so the condition is arr > 5.
Step 2: Match the correct syntax
bool_arr = arr > 5 uses arr > 5, which is correct. arr >= 5 checks greater than or equal to 5, arr == 5 checks equality to 5, and arr < 5 checks less than 5.
Final Answer:
bool_arr = arr > 5 -> Option A
Quick Check:
Condition for > 5 is arr > 5 [OK]
Hint: Use comparison operators directly on arrays for boolean arrays [OK]