If you retain nothing else from this page, retain these 22 lines.
linalg.solve(A, b, assume_a='pos')SPD systems, 2x faster. Never inv().
lu_factor / cho_factor → lu_solveFactor once, solve many.
minimize(f, x0, method='L-BFGS-B', bounds=...)The default reach for smooth + bounds.
curve_fit(model, x, y, p0=[...])Always pass p0. Errors = sqrt(diag(cov)).
root_scalar(f, bracket=[a, b])Brentq. Guaranteed to converge.
solve_ivp(rhs, (t0,t1), y0, dense_output=True)rhs(t, y). LSODA if stiffness unknown.
quad(f, a, b) → (value, error)dblquad's integrand is f(y, x).
make_interp_spline(x, y, k=3)Not interp1d. That's legacy.
rv = stats.norm(loc, scale); rv.sf(x)sf, not 1 - cdf.
ttest_ind(a, b, equal_var=False)Welch. The default is not what you want.
stats.bootstrap / permutation_testWhen no test exists, resample.
fft.rfft(x) + fft.rfftfreq(n, 1/fs)Real input → half spectrum. workers=-1.
butter(N, Wn, fs=fs, output='sos')Always 'sos'. Always pass fs.
sosfiltfilt(sos, x)Zero-phase offline. sosfilt for streaming.
welch(x, fs, nperseg=1024)Averaged PSD. periodogram is the noisy one.
find_peaks(x, prominence=...)prominence > height.
Build COO/DOK → .tocsr() → computeNever mutate a CSR in a loop.
csr_array, not csr_matrix`*` means elementwise on arrays.
spla.spsolve(A.tocsc(), b)Direct sparse solve wants CSC.
KDTree(P).query(q, k, workers=-1)Missing = (inf, tree.n).
special.logsumexp / expit / gammalnStable versions. Never hand-roll.
rng=np.random.default_rng(0)SPEC-7. Not seed=, not random_state=.