gpt4 book ai didi

python - 当掩码为一个时,numpy 更改数组值

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

我是 numpy 的新手,遇到了麻烦。

我有两个 numpy 数组,img 和 thr:

>>>img.shape
(2448, 3264, 3)
>>>thr.shape
(2448, 3264)

我想做这样的事情:设置img[x,y] = [255,255,255]仅当 thr[x,y] is not 0

我尝试遍历数组并自己完成,但这需要很长时间,所以我真的需要 numpy 下面的 C。我也看过屏蔽数组,但我不明白如何使用它们。

谢谢!

最佳答案

使用 NumPy assignment to an indexed array :

img[thr != 0] = [255,255,255]

关于python - 当掩码为一个时,numpy 更改数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13659401/

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