gpt4 book ai didi

python - 在 `numpy.where` 上调用 `masked_array`

转载 作者:太空宇宙 更新时间:2023-11-04 00:53:11 25 4
gpt4 key购买 nike

这是一个例子:

import numpy
from numpy import arange, where
from numpy.ma import masked_array

a = masked_array(arange(10), arange(10) < 5)
print(where((a <= 6))[0])

预期输出:

[5, 6]

实际输出:

[0, 1, 2, 3, 4, 5, 6]

我怎样才能达到预期的输出?谢谢! :)

最佳答案

您只需要使用“numpy.ma.where”来处理屏蔽数组:

print(numpy.ma.where((a <= 6))[0])

关于python - 在 `numpy.where` 上调用 `masked_array`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36216084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com