【问题标题】:Can't find values in my array with numpy.where无法使用 numpy.where 在我的数组中找到值
【发布时间】:2022-12-10 18:54:25
【问题描述】:

我有一个 numpy 维度数组 (30435615,3),其中包含例如 (0.0 0.0 0.0 1) 表示的坐标,我正在寻找一种方法来将坐标包含在另一个数组中的索引设置为 True。我尝试使用 numpy.where 方法,但遇到了一些问题。 如果我打印数组的第 50 个元素,我得到:

>>> print(coordsRAS[50,:])
[-165.31173706    7.91322422 -271.87799072]

但是如果我搜索这一点:

>>> import numpy as np
>>> print(np.where((coordsRAS[:,0]==-165.31173706) & (coordsRAS[:,1] == 7.91322422) & (coordsRAS[:,2] == -256.87799072)))
(array([], dtype=int64),)

我不明白为什么它找不到重点。

【问题讨论】:

    标签: python arrays numpy


    【解决方案1】:

    & 是 AND 按位运算符,也许您需要 | - OR?

    np.where((coordsRAS[:,0]==-165.31173706) | (coordsRAS[:,1] == 7.91322422) | (coordsRAS[:,2] == -256.87799072)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-21
      • 2012-12-26
      • 2020-09-14
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多