Challenge - 5 Problems
Boolean Type Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Boolean Array Comparison
What is the output of this code snippet using NumPy Boolean arrays?
NumPy
import numpy as np arr = np.array([1, 2, 3, 4, 5]) result = arr > 3 print(result)
Attempts:
2 left
💡 Hint
Think about which numbers in the array are greater than 3.
✗ Incorrect
The expression 'arr > 3' compares each element to 3 and returns True if greater, else False.
❓ data_output
intermediate2:00remaining
Count True Values in Boolean Array
What is the output of this code that counts True values in a NumPy Boolean array?
NumPy
import numpy as np bool_arr = np.array([True, False, True, True, False]) count = np.sum(bool_arr) print(count)
Attempts:
2 left
💡 Hint
Sum of Boolean True values counts how many Trues are in the array.
✗ Incorrect
In NumPy, True is treated as 1 and False as 0, so sum counts True values.
🔧 Debug
advanced2:00remaining
Identify the Error in Boolean Indexing
What error does this code raise when trying to index a NumPy array with a Boolean list?
NumPy
import numpy as np arr = np.array([10, 20, 30, 40]) index = [True, False, True] print(arr[index])
Attempts:
2 left
💡 Hint
Check if the Boolean list length matches the array length.
✗ Incorrect
Boolean indexing requires the Boolean array to be the same length as the array being indexed.
❓ visualization
advanced3:00remaining
Visualize Boolean Mask on Data
Which option shows the correct Boolean mask applied to filter values greater than 50 from this NumPy array?
NumPy
import numpy as np import matplotlib.pyplot as plt values = np.array([10, 55, 30, 70, 45, 90]) mask = values > 50 filtered = values[mask] plt.bar(range(len(filtered)), filtered) plt.show()
Attempts:
2 left
💡 Hint
The mask selects values greater than 50 only.
✗ Incorrect
The mask filters values > 50, so only 55, 70, and 90 remain and are shown in the bar chart.
🧠 Conceptual
expert2:30remaining
Boolean Type Memory Usage in NumPy
Which statement correctly describes the memory usage of a NumPy array with dtype=bool compared to dtype=int8?
Attempts:
2 left
💡 Hint
Consider how NumPy stores Boolean values internally.
✗ Incorrect
NumPy stores Boolean arrays using 1 byte per element, not 1 bit, so memory usage equals int8 arrays.