dpnp.diff
- dpnp.diff(a, n=1, axis=-1, prepend=None, append=None)[source]
Calculate the n-th discrete difference along the given axis.
For full documentation refer to
numpy.diff
.- Parameters:
a ({dpnp.ndarray, usm_ndarray}) -- Input array
n ({int}, optional) -- The number of times the values differ. If
zero
, the input is returned as-is.axis ({int}, optional) -- The axis along which the difference is taken, default is the last axis.
prepend ({None, scalar, dpnp.ndarray, usm_ndarray}, optional) -- Values to prepend or append to a along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match a except along axis.
append ({None, scalar, dpnp.ndarray, usm_ndarray}, optional) -- Values to prepend or append to a along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match a except along axis.
- Returns:
out -- The n-th differences. The shape of the output is the same as a except along axis where the dimension is smaller by n. The type of the output is the same as the type of the difference between any two elements of a. This is the same as the type of a in most cases.
- Return type:
dpnp.ndarray
See also
dpnp.gradient
Return the gradient of an N-dimensional array.
dpnp.ediff1d
Compute the differences between consecutive elements of an array.
dpnp.cumsum
Return the cumulative sum of the elements along a given axis.
Examples
>>> import dpnp as np >>> x = np.array([1, 2, 4, 7, 0]) >>> np.diff(x) array([ 1, 2, 3, -7]) >>> np.diff(x, n=2) array([ 1, 1, -10])
>>> x = np.array([[1, 3, 6, 10], [0, 5, 6, 8]]) >>> np.diff(x) array([[2, 3, 4], [5, 1, 2]]) >>> np.diff(x, axis=0) array([[-1, 2, 0, -2]])