【问题标题】:np.diff(np.signbit()) no longer finds zero crossings, better way?np.diff(np.signbit()) 不再找到过零,更好的方法?
【发布时间】: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


【解决方案1】:

这显然在 1.14.0 中已修复,但作为一种快速修复显式类型转换:

zcs = np.diff(np.signbit(A).astype(int), axis=1) 

应该可以。

【讨论】:

    猜你喜欢
    • 2013-10-16
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 2016-02-22
    • 2016-04-12
    • 1970-01-01
    相关资源
    最近更新 更多