Introduction to Boolean Indexing

Hello! We'll explore a concept called Boolean Indexing in NumPy today. It lets us access array elements based on conditions instead of explicit indices.

Practice with Boolean Indexing: Dataset

To illustrate, let's create a NumPy array, data:

Practice with Boolean Indexing: Boolean Mask

Now, suppose we want to extract elements greater than 30. We form a Boolean array checking this condition for data:

Practice with Boolean Indexing: Selecting Data

To extract the elements that satisfy our condition from data, we use the bool_array as an index:

Now filtered_data only holds values from that are greater than 30.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal