numpy 矩阵赋值的问题

lower_green = np.array([0,200,0]) 
upper_green = np.array([100,255,100])

img=np.zeros((2,2,3))

for pos in img:
    for color in pos:
        color = lower_green
        print(color)
        #

print(img)
plt.imshow(img)

>> [  0 200   0]
[  0 200   0]
[  0 200   0]
[  0 200   0]


>>[[[ 0.  0.  0.]
  [ 0.  0.  0.]]

 [[ 0.  0.  0.]
  [ 0.  0.  0.]]]

为什么矩阵没有改变呢,如果采用 color[0]=lower_green[0]就可以改变 img 矩阵

阅读 11.1k
1 个回答
In [24]: import numpy as np

In [25]: np.full((2,2,3), [100,255,100])
Out[25]: 
array([[[100, 255, 100],
        [100, 255, 100]],

       [[100, 255, 100],
        [100, 255, 100]]])
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题