Detect outliers with 3-Sigma rule, filter datasets, and compute group statistics.
NumPy provides the core statistical tools to clean messy real-world datasets: detecting outliers using the 3-Sigma Rule ($|X - \mu| > 3\sigma$) and filling missing values.
The 3-Sigma rule is a statistical metal detector: 99.7% of normal data falls within 3 standard deviations; anything beyond is flagged as an outlier.
Values where `np.abs(data - mean) > 3 * std` are statistical anomalies that distort model training.
clean = data[np.abs(data - data.mean()) <= 3 * data.std()]clean = [x for x in data if x < 50] # Slow list comprehensionclean = data[data < 50]NumPy boolean indexing is 50x faster than Python list filtering.
Solve the objective below using NumPy vectorized syntax
Create `arr = np.array([5, 25, 80, 40])`, clip values into `[10, 50]` with `np.clip(arr, 10, 50)`, and print.
[10 25 50 40]