Set your Publisher ID in src/config/ads.ts to display live ads.
Multi-Dimensional Indexing, Slicing & Boolean Masking
Views vs Copies, strided slicing, and conditional data filtering
NumPy indexing allows multi-axis extraction using syntax arr[row_slice, col_slice]. Slices create memory views rather than copies.
Views vs Copies & Boolean Masking
Views: Basic slicing (arr[0:2, 1:3]) returns a view of the original memory. Modifying elements in the slice modifies the original array! Use .copy() if you need an isolated clone.
Boolean Masking: Filtering arrays with conditional expressions (arr[arr > 50]) evaluates vectorized boolean conditions and extracts matching elements.
Fancy Indexing: Passing integer arrays (arr[[0, 2, 3]]) extracts arbitrary rows or columns and returns a copy.
import numpy as np
scores = np.array([88, 42, 95, 61, 38, 77, 90])
# Extract only passing grades (>= 60)
passing = scores[scores >= 60]
print("Passing scores:", passing)
# Cap all scores below 50 to 50 (vectorized mutation)
scores[scores < 50] = 50
print("Curved scores:", scores)Basic slicing returns a view. Fancy indexing (indexing with an array of indices) always returns a new copy.
Set your Publisher ID in src/config/ads.ts to display live ads.
Test Yourself With Exercise
What happens to the original array if you mutate values inside a standard basic slice `sub = arr[0:2, :]`?