在对 Numpy 数组执行条件索引时,我不理解弃用警告错误,希望能得到一些澄清,希望它也能造福于社区。让我们考虑一个名为“block”的 NumPy 数组,其中包含从 1 到 12 的整数:
block = np.arange(1,13)
我可以通过执行以下操作来选择不同于 4 的值:
selection = block[block != 4]
现在我想选择不同于 1、4 和 7 的值。如果我这样做:
selection = block[block != np.array([1, 4, 7])]
我收到以下错误:
__main__:1: DeprecationWarning: elementwise != comparison failed; this will
raise an error in the future.
__main__:1: VisibleDeprecationWarning: using a boolean instead of an integer
will result in an error in the future
谁能解释这个警告的原因,并指定执行此切片的正确方法(理想情况下,建议的解决方案也应该适用于尝试从大型 numpy 数组中提取与另一个大型 numpy 数组中的值不同的值时)?请注意,警告后 select = 2 ,我也不明白。