linalg:diff
(linalg:diff array &optional n)
Returns the n-th discrete difference along the last axis (numpy's np.diff): each output element is a[..., i+1] - a[..., i], applied n times (default 1), so each step shortens the last axis by one. It works for any rank -- a matrix differences within each row -- and the result is a fresh packed array of the input's width (#f stays #f). n of 0 returns a packed copy. For a derivative estimate that keeps the input length, use linalg:gradient.