在numpy数组上使用布尔运算的可见弃用警告

时间:2016-07-29 10:15:44

标签: python arrays numpy boolean-operations

我遇到了一个问题,我一直收到警告:

x_low = xcontacts[(xcontacts[5:6] <= 2000).any(1), :]
x_med = xcontacts[(xcontacts[5:6] <= 4000).any(1), :]
x_med = xcontacts[(xcontacts[5:6] > 2000).any(1), :]
x_hi  = xcontacts[(xcontacts[5:6] > 4000).any(1), :]

当我尝试使用它时:

xcontacts.shape
Out[46]: (744L, 6L)

在一个形状数组上:

[[   1.        0.        0.        4.        0.      228.681 ]
 [   2.        4.        0.        8.        0.      219.145 ]
 [   3.        8.        0.       12.        0.      450.269 ]
 ..., 
 [  60.      236.       96.      240.       96.      933.4565]
 [  61.      240.       96.      244.       96.      646.449 ]
 [  62.      244.       96.      248.       96.      533.657 ]]

这是一个数组样本:

x_low where col5 <= 2000
x_med where 2000 < col5 <= 4000
x_hi where 4000 < col5

我尝试创建三个新数组,这些数组是第一个的副本,但是在对最终列执行了布尔操作之后,删除了与运算符不一致的行:

{{1}}

有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

感谢@Syrtis Major:

x_low = xcontacts[(xcontacts[:,5] <= 2000)]
x_med = xcontacts[(xcontacts[:,5] <= 4000)]
x_med = xcontacts[(xcontacts[:,5] > 2000)]
x_hi  = xcontacts[(xcontacts[:,5] > 4000)]