Explore Library
Code Quiz

Boolean Masking in NumPy

A NumPy filtering snippet fails because of the wrong boolean operators when combining two conditions.

Codepython
import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6])
# keep values strictly between 2 and 6
mask = (arr > 2) and (arr < 6)
result = arr[mask]
print(result)

Why does this code raise an error instead of filtering the array?