这段代码
import numpy as np
def some_method(y, threshold):
print type(y), y.shape, y.dtype
c = np.zeros(y.shape)
c[y > threshold] = 1
结果是
<type 'numpy.ndarray'> (484L,) [('target', '<f8')]
DeprecationWarning: using a boolean instead of an integer will result in an error in the future
c[y > threshold] = 1
我在 Google 和 numpy 发行说明中都找不到任何相关内容。我假设这是关于布尔索引?我不明白这怎么可能导致将来出现错误,我该如何解决这个问题?
Python 2.7.6(默认,2013 年 11 月 10 日,19:24:24)[MSC v.1500 64 位 (AMD64)] 在 win32 上
numpy版本:1.8.0
编辑:在代码中添加了 print 语句以显示该数组是一个 ndarray
EDIT2:从评论中可以清楚地看出,发生这种情况是因为y
是一个结构体数组,正确的检查方法是y['target'] > threshold
。然而,y
可以有多个列,甚至不同的列名,有没有办法使用结构化数组灵活地做到这一点?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)