我有以下设置,其中有2d numpy数组,我想更新每一行和匹配的列。
import numpy as np
image = np.array([[0, 0, 1, 1],
[0, 0, 1, 1],
[0, 0, 1, 1],
[0, 0, 1, 1],
[0, 0, 1, 1]])
cols = [1, 1, 2, 2, 2]
image[:, cols] = 255
print image
希望产生:
[[ 0 255 1 1]
[ 0 255 1 1]
[ 0 0 255 1]
[ 0 0 255 1]
[ 0 0 255 1]]
结果与预期不同:
[[ 0 255 255 1]
[ 0 255 255 1]
[ 0 255 255 1]
[ 0 255 255 1]
[ 0 255 255 1]]