Closed
Description
It seems that numpy.gradient() computes the boundary values incorrectly in version 1.9.0 (but correctly in e.g. version 1.8.1)
To reproduce:
Alternative 1:
>>> x = np.array([1, 2, 4], dtype=np.float)
>>> np.gradient(x)
array([ 0.5, 1.5, 2.5])
although the resulting array should be [(2-1)/1, (4-1)/2, (4-2)/1] = [1, 1.5, 2]
Alternative 2:
Just run the first example in the documentation for numpy.gradient():
>>> x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float)
>>> np.gradient(x)
The result is
array([ 0.5, 1.5, 2.5, 3.5, 4.5, 5.5])
although the documentation says that it should be
array([ 1. , 1.5, 2.5, 3.5, 4.5, 5. ])
the latter also seems right, while the former seems wrong.