[Numpy-discussion] Changed behavior of np.gradient

Ariel Rokem arokem at gmail.com
Sat Oct 4 14:37:05 EDT 2014


Hi everyone,

>>> import numpy as np

>>> np.__version__

'1.9.0'

>>> np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float))

[array([[ 2.,  2., -1.],

       [ 2.,  2., -1.]]), array([[-0.5,  2.5,  5.5],

       [ 1. ,  1. ,  1. ]])]


On the other hand:

>>> import numpy as np

>>> np.__version__

'1.8.2'

>>> np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float))

[array([[ 2.,  2., -1.],

       [ 2.,  2., -1.]]), array([[ 1. ,  2.5,  4. ],

       [ 1. ,  1. ,  1. ]])]


For what it's worth, the 1.8 version of this function seems to be in
agreement with the Matlab equivalent function ('gradient'):

>> gradient([[1, 2, 6]; [3, 4, 5]])


ans =


    1.0000    2.5000    4.0000

    1.0000    1.0000    1.0000

This seems like a regression to me, but maybe it's an improvement?

Cheers,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141004/1651bbf0/attachment.html>


More information about the NumPy-Discussion mailing list