Where the plan stops: scipy.stats inside a LazyFrame
scipy.stats already handles per-row distributions. Pass arrays as the parameters and a frozen distribution
broadcasts them against the evaluation points, so scoring each sensor reading against its own sensor's baseline is
one call:
import numpy as np
from scipy import stats
reading = np.array([9.8, 10.4, 135.0])
mu = np.array([10.0, 10.0, 100.0])
sigma = np.array([0.5, 0.5, 2.0])
print(stats.norm(loc=mu, scale=sigma).sf(reading))
For the arithmetic, a Polars user needs nothing more. The trouble starts with where the result lands, which is a NumPy array, outside both the query plan and the expression API.