`np.diff` is broken for boolean ndarrays in 1.13.0
See original GitHub issueShould modify the docstring accordingly, raise a meaningful error, or (preferably) make it work by hidding some logic under the hood.
Traceback:
In [11]: x = np.array([[True, True], [False, False]])
In [12]: np.diff(x)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-12-59225436601c> in <module>()
----> 1 np.diff(x)
/usr/lib/python3.6/site-packages/numpy/lib/function_base.py in diff(a, n, axis)
1924 return diff(a[slice1]-a[slice2], n-1, axis=axis)
1925 else:
-> 1926 return a[slice1]-a[slice2]
1927
1928
TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.
In [13]: np.__version__
Out[13]: '1.13.0'
xref https://github.com/scikit-image/scikit-image/issues/2681
Issue Analytics
- State:
- Created 6 years ago
- Comments:29 (29 by maintainers)
Top Results From Across the Web
NumPy 1.13.0 Release Notes
Object arrays that contain list objects are now printed in a way that makes clear the difference between a 2d object array, and...
Read more >How can I convert boolean values from np.diff() to the actual ...
I am attempting to iterate through each value of the array and subtract the 2nd value from the 1st, then see if the...
Read more >Release Notes — NumPy v1.13 Manual
In NumPy 1.13.0, results from such operations are now defined to be the same as for equivalent operations where there is no memory...
Read more >Difficulty installing on Python 3.6 - Support
An error comes up related to test failures due to “numpy boolean subtract.” Is this error is due to using Python 3.6?
Read more >Source code for numpy.ma.core - Astropy
Thankfully, this only makes a difference when arrays are 2- or more- ... Numpy 1.13.0, gh-8701: warn on axis default warnings.warn( "In the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well - I can see the purity argument for disallowing, but it seems to me that it is reasonable to expect diff to work on booleans, and not surprising that scikit image was doing that. So I would have thought a branch on
bool
was the better route.That’s because by default
DeprecationWarning
is not displayed. Add aimport warnings; warnings.simplefilter('always')
and you’ll see it