A robot test report estimates how much each sensor channel varies at a fixed pose. One channel records the same displayed value on three of five samples, with two small changes. Its median absolute deviation is zero. If the report uses that value to normalize each reading, it needs to handle the resulting undefined score and keep the original variations available for review.

Calculate spread per channel

Median absolute deviation, or MAD, takes the median of the absolute departures from a center, usually the median. Here each row is one timestamp and each column is one channel. Reducing over axis 0 gives one center and one MAD per channel. SciPy's normal scaling divides the raw MAD by approximately 0.67449, which puts it on the scale of standard deviation for a normal population. The scaling leaves a zero MAD at zero.

import numpy as np

from scipy.stats import median_abs_deviation

samples = np.array([

[0.18, 2.00],

[0.20, 2.00],

[0.21, 2.00],

[0.19, 2.01],

[0.90, 2.02],

])

center = np.median(samples, axis=0)

spread = median_abs_deviation(samples, axis=0)

normal_scale = median_abs_deviation(samples, axis=0, scale="normal")

scores = np.full(samples.shape, np.nan)

has_scale = spread > 0

scores[:, has_scale] = (samples[:, has_scale] - center[has_scale]) / normal_scale[has_scale]

assert np.allclose(center, [0.20, 2.00])

assert np.allclose(spread, [0.01, 0.0])

assert np.isnan(scores[:, 1]).all()

In SciPy 1.18.1 and NumPy 2.5.2 the channel medians are 0.20 and 2.00, and the raw MAD values are 0.01 and zero. The normal-scaled spreads are approximately 0.014826 and zero. The reading 0.90 in the first channel gives a normalized residual of approximately 47.214. The second channel's normalized residuals stay undefined because the divisor is zero. Its raw readings still include 2.01 and 2.02.

Report the reason a score is missing

Retain the channel name, engineering units, number of finite readings, median, and raw spread next to the normalized result. If a channel has zero spread under this statistic, examine the raw deviations against the resolution and tolerance of that instrument. Exact repeats might reflect quantization or a stable operating condition. More context is needed to tell those apart. Using an arbitrary tiny denominator would make the displayed score depend on that choice.

Include a repeated-value trace in tests for the report, alongside a trace with one planted spike. Check that the axis and channel order stay the same after filtering and export. For logs with missing samples, distinguish a missing score due to zero scale from insufficient observations. Keep the underlying values so reviewers can apply a documented threshold in physical units if the normalized score is unavailable.

Sources

SciPy median_abs_deviation API reference for scale and axis behavior

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.median_abs_deviation.html

NumPy median API reference for reductions by axis

https://numpy.org/doc/stable/reference/generated/numpy.median.html