dpnp.ediff1d

dpnp.ediff1d(ary, to_end=None, to_begin=None)[source]

The differences between consecutive elements of an array.

For full documentation refer to numpy.ediff1d.

Parameters:
  • ary ({dpnp.ndarray, usm_ndarray}) -- 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. Default: None.

  • to_begin (array_like, optional) -- Number(s) to prepend at the beginning of the returned differences. Default: None.

Returns:

out -- New array consisting differences among succeeding elements. Loosely, this is ary.flat[1:] - ary.flat[:-1].

Return type:

dpnp.ndarray

See also

dpnp.diff

Calculate the n-th discrete difference along the given axis.

dpnp.gradient

Return the gradient of an N-dimensional array.

Examples

>>> import dpnp as np
>>> 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,   3,  -7,  88,  99])

The returned array is always 1D.

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