我的numpy数组(名称为data)大小如下:(10L,3L,256L,256L)
。它包含10张图片,每张图片有3个彩色通道(RGB),大小为256x256像素。
我想要计算所有10张图像中每个颜色通道的平均像素值。如果我使用numpy函数np.mean(data)
,我会得到所有像素值的平均值。使用np.mean(data, axis=1)
将返回一个大小为(10L, 256L, 256L)
的numpy数组。
(10,3)
的数组) (如果我的理解有误,请在评论中告诉我,我可以编辑这个答案)np.mean
函数。mean_values = data.mean(axis=(2,3))
mean_values = data.reshape((data.shape[0], data.shape[1], data.shape[2]*data.shape[3])).mean(axis=2)