A robot position log can contain valid measurements at unequal time intervals. Estimating velocity from that log requires the actual time coordinates to remain attached to the position values. Passing a list of elapsed intervals where a function expects sample coordinates, or dividing two index-based gradients, can produce a different calculation from the intended coordinate-aware derivative.
An original NumPy 2.5.2 fixture compares those cases using a noise-free quadratic model. It is a numerical teaching example, with no robot motion, sensor acquisition, or control-loop operation. Agreement with the model's analytic derivative does not establish an accuracy guarantee for a measured log.
Define the four observations and their units
Use time coordinates [0,1,3,6] seconds and position values [0,1,9,36] millimeters. They follow the hypothetical relation x(t)=c times t squared, with c equal to 1 millimeter per second squared. The analytic velocity is 2c times t, giving [0,2,6,12] millimeters per second at the four sample times.
The adjacent time gaps are [1,2,3] seconds. Those three intervals describe separations between four observations. They are not another four-element coordinate vector. The distinction is structural before any numerical approximation is considered.
Use the coordinate-array interface
NumPy's gradient reference distinguishes a scalar spacing from arrays of coordinates. For an array argument, its length must match the corresponding data dimension. The reference also distinguishes the interior central-difference calculation from the one-sided boundary rules selected by edge_order.
The executed fixture calls gradient with the four positions and the four time coordinates, setting edge_order=2. It returns [0,2,6,12] within floating-point tolerance. These values match the analytic derivative for this particular quadratic construction, including the endpoints.
This is a property of the declared model and difference formulas, not proof that adding edge_order=2 recovers a true derivative from arbitrary noisy measurements. The fixture uses exact invented timestamps and no missing samples, noise, clock drift, or trajectory discontinuity.
Keep the boundary choice in the receipt
Repeating the coordinate-aware call with edge_order=1 returns [1,2,6,9]. The two interior values remain 2 and 6, while the endpoint estimates change. Comparing only the interior results would miss this effect of the selected boundary rule.
At the first boundary, the first two positions differ by 1 millimeter over 1 second. At the final boundary, the last two positions differ by 27 millimeters over 3 seconds. The resulting endpoint quotients are therefore 1 and 9 millimeters per second, as observed in the first-order call.
Those endpoint values have a clear interval interpretation for this construction, even though they do not equal the analytic instantaneous velocities at times 0 and 6. A review should state the estimator and timestamp assignment instead of treating every returned number as the same kind of observation.
Inspect one unequal-spacing interior calculation
At time 1, the preceding time gap is 1 second and the following gap is 2 seconds. The coordinate-aware interior expression gives weights of -2/3, 1/2, and 1/6 per second to the positions at times 0, 1, and 3 respectively.
Applying those weights to [0,1,9] gives 0 plus 0.5 plus 1.5, or 2 millimeters per second. Their sum is zero, so an equal constant offset added to all three positions contributes nothing to this particular derivative estimate. The asymmetric weights reflect the asymmetric time gaps.
By contrast, the secant across the two neighboring observations is (9-0)/(3-0), or 3 millimeters per second. That quotient describes the average change over the full three-second interval. It is a different quantity from the model's instantaneous velocity at the interior time of 1 second.
Replay the ratio shortcut separately
The fixture also evaluates gradient(position) divided elementwise by gradient(time), using each call's default boundary rule and implicit unit index spacing. It produces [1,3,7,9]. In particular, its interior values are 3 and 7 instead of the coordinate-aware values 2 and 6.
At an interior point, this ratio cancels the equal index-space denominator and becomes a secant across the neighboring samples. On unequal time gaps, that is not the same weighting used by the coordinate-aware call. The output can have velocity units while still answering a different numerical question.
This comparison does not label every ratio method invalid. It demonstrates that the shortcut is not an interchangeable implementation of this coordinate-aware derivative on the declared nonuniform grid. Any chosen estimator should carry its own mathematical interpretation and validation evidence.
Do not substitute the gap vector
NumPy's diff reference defines adjacent differences. Applying it to the four times yields the three-element gap array [1,2,3]. Passing that array as gradient's coordinate argument for the four positions raises ValueError on the tested runtime because the lengths do not match.
Adding an arbitrary fourth gap to make the shapes agree would not resolve the meaning. A coordinate vector identifies where each value was sampled; a gap vector describes separations between values. A proposed importer should preserve the original timestamps and construct coordinates deliberately when only interval data are available.
Validate the proposed input contract first
For this example, the fixture verifies finite times and strictly positive adjacent time differences. A real review would also need a declared rule for duplicate times, out-of-order records, missing positions, and units. The numerical outputs here do not validate any automatic repair of those cases.
Preserve each position's association with its time when sorting or rejecting records under that declared rule. A plausible-looking four-element array is not enough evidence that the corresponding positions and coordinates belong together. The current fixture avoids such repair decisions so it can isolate the estimator difference.
Save the estimator alongside the values
The replay receipt includes the four times and positions, units, adjacent gaps, analytic-model coefficient, coordinate-aware outputs for both boundary choices, ratio-shortcut output, invalid-gap exception, and the explicit interior weights. Python 3.14.7 and NumPy 2.5.2 produced the local calculation.
The practical lesson is to supply coordinates when the interface asks for coordinates. With uneven observations, retaining those times and the boundary rule explains why two velocity arrays differ. Matching one synthetic quadratic verifies this example; it does not turn a numerical derivative into a separate measurement of actual robot velocity.
Sources checked November 18, 2026:
NumPy, numpy.gradient, version 2.5 manual:
https://numpy.org/doc/stable/reference/generated/numpy.gradient.html
NumPy, numpy.diff, version 2.5 manual:
https://numpy.org/doc/stable/reference/generated/numpy.diff.html
The times, quadratic model, calculations, and input-review proposal are original T-800 editorial work. No source example or measured robot log is reproduced.
Illustration: an AI-generated conceptual table keeps synthetic times and positions aligned with one coordinate-aware derivative result. It is not a measurement chart or validated robot trajectory.