numpy.gradient

numpy.gradient(f, *varargs)

Return the gradient of an N-dimensional array.

The gradient is computed using central differences in the interior and first differences at the boundaries. The returned gradient hence has the same shape as the input array.

Parameters:

f : array_like

An N-dimensional array containing samples of a scalar function.

`*varargs` : scalars

0, 1, or N scalars specifying the sample distances in each direction, that is: dx, dy, dz, ... The default distance is 1.

Returns:

g : ndarray

N arrays of the same shape as f giving the derivative of f with respect to each dimension.

Examples

>>> np.gradient(np.array([[1,1],[3,4]]))
[array([[ 2.,  3.],
       [ 2.,  3.]]),
 array([[ 0.,  0.],
       [ 1.,  1.]])]

Previous topic

numpy.ediff1d

Next topic

numpy.cross

This Page

Quick search