python - 选择 x 为 nan 而 y 介于两个值之间的索引

标签 python numpy

我有两个数组

x = np.array([1,np.nan,3,np.nan,5])
y = np.array([1,-2,3,4,15])

现在我想仅选择 x = np.nan 的索引,其中 y 位于 010。分别像这样:

np.where(isnan(x))
(array([1,3])
np.where(y>=0)
(array([0, 2, 3, 4])
np.where(y<10)
(array([0, 1, 2, 3])

但是要做什么才能得到:

(array[3])

最佳答案

您需要在条件中使用括号(由于运算符优先级)和按位 & 运算符来表示 AND:

In [3]:

np.where(isnan(x) & (y >=0) & (y<10))
Out[3]:
(array([3], dtype=int64),)

关于python - 选择 x 为 nan 而 y 介于两个值之间的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22756236/

相关文章:

python - 使用 mechanize 和 urllib 下载 pdf 文件

python - CouchDB 中的无状态分页?

python - 替换OpenCV中多个RGB值的所有像素

javascript - 谷歌分析非法 cookie 破坏 Python 后端

python - 使用 python 从 xml 填充列表

python - 为什么没有 OpenBLAS 的 numpy/scipy 更快?

arrays - 如何使用另一个向量的值从 numpy 矩阵中选择列

python - 矩阵乘以 block

python - 如何从系数列表构建多项式 lambda 函数?

Python:如何添加两个列表,其中与该键的值相同的键没有重复值?