Back to Practice
#0170

Filter Rows With a Boolean Mask

EasyNumPy15 min10 XP

Problem

Given a 2D array X, return rows where the first column is greater than threshold.

Why This Matters

Boolean masks are the foundation of vectorized filtering in NumPy, Pandas, and ML preprocessing.

Function Signature

def filter_first_col(X, threshold):

Examples

Example 1
InputX = np.array([[1,10],[5,20],[3,30]]), threshold = 2
Outputnp.array([[5,20],[3,30]])

Rows with first-column values 5 and 3 are kept.

Constraints

  • Return the exact requested output.
  • Handle ordinary edge cases.
  • Prefer simple, interview-readable code.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
InputX = np.array([[1,10],[5,20],[3,30]]), threshold = 2
Expectednp.array([[5,20],[3,30]])

Rows with first-column values 5 and 3 are kept.

Hidden Test Categories
empty or minimal inputduplicates or tieslarger input