我有一个形状(100,320,320)
的numpy数组,100个图像,每个图像是320 * 320。
我尝试过:
mean = np.mean(train_x)
train_x -= mean
我得到Cannot cast ufunc subtract output from dtype('float64') to dtype('uint8') with casting rule 'same_kind'
有人可以指导我如何实现这个目标吗?
答案 0 :(得分:0)
允许结果为浮点数:
mean = np.mean(train_x)
train_x = train_x - mean
或者将平均值计算为np.uint8
(失去精度):
mean = np.mean(train_x, dtype=train_x.dtype)
train_x -= mean