gpt4 book ai didi

python - 这种NumPy列表理解的捷径

转载 作者:行者123 更新时间:2023-12-02 16:56:24 26 4
gpt4 key购买 nike

有没有更简单,更快速的方法?

maxr, maxc = im_out.shape[:2]

for col in range(maxc):
for row in range(maxr):
if im_gray[row,col,0] != 255 and im_gray[row,col,1] != 255 and im_gray[row,col,2] != 255:
im_out[row, col] = im_gray[row, col]

最佳答案

遵循以下方法应该可以解决问题:

# I think it's axis 2, might have to play around there
mask = (im_gray != 255).all(axis=2)
im_out[mask] = im_gray[mask]

关于python - 这种NumPy列表理解的捷径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30437547/

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