Week 2 • Wednesday

Block 15: Boolean Masks & Fancy Indexing

Filter arrays using conditions; use index arrays.

Concepts

Code Examples

See exercise below.

Exercise

From 0–99, extract: values between 20–50, values NOT divisible by 3. Replace all values below 10 with 0 in a random array.

Homework

Use np.where to create a new array where positive values stay, negative become -1.