[英]NumPy boolean array warning?
I have a few numpy arrays, lets say a
, b
, and c
, and have created a mask
to apply to all of them. 我有一些numpy数组,比如
a
, b
和c
,并创建了一个mask
来应用于所有这些数组。
I am trying to mask them as such: 我试图掩盖它们:
a = a[mask]
where mask
is a bool
array. 其中
mask
是bool
数组。 It is worth noting that I have verified that 值得注意的是,我已经证实了这一点
len(a) = len(b) = len(c) = len(mask)
And I am getting a rather cryptic sounding warning: 我收到了一个相当神秘的警告:
FutureWarning: in the future, boolean array-likes will be handled as a boolean array index
False == 0, and True == 1. If your mask is a list, and not an ndarray, you can get some unexpected behaviour: False == 0,True == 1.如果你的掩码是一个列表,而不是一个ndarray,你可能会得到一些意想不到的行为:
>>> a = np.array([1,2,3])
>>> mask_list = [True, False, True]
>>> a[mask_list]
__main__:1: FutureWarning: in the future, boolean array-likes will be handled as a boolean array index
array([2, 1, 2])
where this array is made up of a[1], a[0], and a[1], just like 这个数组由[1],[0]和[1]组成,就像
>>> a[np.array([1,0,1])]
array([2, 1, 2])
On the other hand: 另一方面:
>>> mask_array = np.array(mask_list)
>>> mask_array
array([ True, False, True], dtype=bool)
>>> a[mask_array]
array([1, 3])
The warning is telling you that eventually a[mask_list]
will give you the same as a[mask_array]
(which is probably what you wanted it to give you in the first place.) 警告告诉你,
a[mask_list]
最终会给你a[mask_array]
(这可能是你想要它首先给你的。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.