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