mindspore.numpy.ediff1d

View Source On Gitee
mindspore.numpy.ediff1d(ary, to_end=None, to_begin=None)[source]

The differences between consecutive elements of a tensor.

Parameters
  • ary (Tensor) – If necessary, will be flattened before the differences are taken.

  • to_end (Tensor or scalar, optional) – Number(s) to append at the end of the returned differences.

  • to_begin (Tensor or scalar, optional) – Number(s) to prepend at the beginning of the returned differences.

Returns

The differences.

Raises

TypeError – If inputs have types not specified above.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> arr = np.array([1, 3, -1, 0, 4])
>>> print(np.ediff1d(arr))
[ 2 -4  1  4]