# jax.numpy.ediff1dÂ¶

jax.numpy.ediff1d(ary, to_end=None, to_begin=None)[source]Â¶

The differences between consecutive elements of an array.

LAX-backend implementation of ediff1d(). Unlike NumPyâ€™s implementation of ediff1d, jax.numpy.ediff1d() will not issue an error if casting to_end or to_begin to the type of ary loses precision.

Original docstring below.

Parameters
• ary (array_like) â€“ If necessary, will be flattened before the differences are taken.

• to_end (array_like, optional) â€“ Number(s) to append at the end of the returned differences.

• to_begin (array_like, optional) â€“ Number(s) to prepend at the beginning of the returned differences.

Returns

ediff1d â€“ The differences. Loosely, this is ary.flat[1:] - ary.flat[:-1].

Return type

ndarray

Notes

When applied to masked arrays, this function drops the mask information if the to_begin and/or to_end parameters are used.

Examples

>>> x = np.array([1, 2, 4, 7, 0])
>>> np.ediff1d(x)
array([ 1,  2,  3, -7])

>>> np.ediff1d(x, to_begin=-99, to_end=np.array([88, 99]))
array([-99,   1,   2, ...,  -7,  88,  99])


The returned array is always 1D.

>>> y = [[1, 2, 4], [1, 6, 24]]
>>> np.ediff1d(y)
array([ 1,  2, -3,  5, 18])