小编blu*_*lub的帖子

np.where和掩码数组

由于我在stackoverflow上获得了一些帮助,因此我正在使用蒙版数组,但是我在使用np.where评估蒙版数组时遇到了问题。

我的蒙版数组是:

m_pt0 = np.ma.masked_array([1, 2, 3, 0, 4, 7, 6, 5],
                           mask=[False, True, False, False,
                                 False, False, False, False])
Run Code Online (Sandbox Code Playgroud)

并打印如下:

In [24]: print(m_pt0)
[1 -- 3 0 4 7 6 5]
Run Code Online (Sandbox Code Playgroud)

我正在寻找m_pt0中的索引,其中m_pt0 = 0,我希望

np.where(0 == m_pt0)
Run Code Online (Sandbox Code Playgroud)

会返回:

(array([3]))
Run Code Online (Sandbox Code Playgroud)

但是,尽管戴了口罩(或因为?),我反而得到了

(array([1, 3]),)
Run Code Online (Sandbox Code Playgroud)

使用掩码的全部目的是避免访问“空白”的索引,因此如何使用where(或其他函数)仅检索未掩码且与我的布尔条件匹配的索引。

python arrays numpy boolean-operations masked-array

2
推荐指数
1
解决办法
2170
查看次数

如何通过python中的文本获取xpath

我们很容易通过 获取文本xpath,但是有什么方法可以xpath通过textPython?

例如。

 <html><h1>Hello World</h1></html>
Run Code Online (Sandbox Code Playgroud)

如何获得xpath通过Hello World

python

-1
推荐指数
1
解决办法
3959
查看次数

标签 统计

python ×2

arrays ×1

boolean-operations ×1

masked-array ×1

numpy ×1