如果我在numpy中有一个3维矩阵,并且想要使用切片仅更改某个维度的某些值,那可能吗?这就是我所拥有的,但在运行代码后,这些值是未经修改的:
import numpy as np
from scipy import misc
image_matrix_data = misc.imread('./some-image.jpg')
image_mask = image_matrix_data[:, : ,0] < 150
image_matrix_data[image_mask][:,0] = 0
# expected to get a matrix where several of the values in
# image_matrix_data[:, :, 0] are now 0, but not happening
我错过了什么吗?
答案 0 :(得分:1)
上述Divakar的回答:
import numpy as np
from scipy import misc
image_matrix_data = misc.imread('./some-image.jpg')
image_mask = image_matrix_data[:, : ,0] < 150
image_matrix_data[image_mask, 0] = 0