<p>这是原始文档的摘录(在编写本文时,可在<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.gradient.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.gradient.html</a>找到)。它指出,除非采样距离为1,否则需要包含包含距离的列表作为参数。</p>
<blockquote>
<pre><code>numpy.gradient(f, *varargs, **kwargs)
</code></pre>
<p>Return the gradient of an N-dimensional array.</p>
<p>The gradient is computed using second order accurate central differences in the interior and either first differences or second order accurate one-sides (forward or backwards) differences at the boundaries. The returned gradient hence has the same shape as the input array.</p>
<p>Parameters:<br/>
f : array_like
An N-dimensional array containing samples of a scalar function.</p>
<p>varargs : list of scalar, optional
N scalars specifying the sample distances for each dimension, i.e. dx, dy, dz, ... Default distance: 1.</p>
<p>edge_order : {1, 2}, optional
Gradient is calculated using Nth order accurate differences at the boundaries. Default: 1.
New in version 1.9.1.</p>
<p>Returns:<br/>
gradient : ndarray
N arrays of the same shape as f giving the derivative of f with respect to each dimension.</p>
</blockquote>