【发布时间】:2018-06-25 21:56:12
【问题描述】:
这answer 是我正在寻找的,但由于布尔减法已被贬值,它不再有效。有没有更好的办法?
A = np.array([[-2, -1, 1],
[-1, 0, 1],
[-1, 1, 2]], dtype=float)
zcs = np.diff(np.signbit(A), axis=1) # find zero crossings in each row - now fails
生成:
Traceback (most recent call last):
File "/Users/david/Documents/wow.py", line 4, in <module>
zcs = np.diff(np.signbit(A), axis=1) # now fails
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/function_base.py", line 1926, in diff
return a[slice1]-a[slice2]
TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.
【问题讨论】:
-
对我来说没有错误。你的 NumPy 版本是多少?
-
@Divakar '1.13.0'
-
升级到 1.14.0?
-
不,我很好 :) 这篇文章没有添加任何新内容,所以不妨删除这篇文章。
-
无论如何,
zcs = np.diff(np.signbit(A).astype(int), axis=1)应该可以工作。
标签: python-2.7 numpy