我试图对我的数据集执行平均聚类。数据集 X 的维度为 (182,108,130)。使用 np.mean(X, axis = 1) 计算平均值。平均值的维度为 (182,130)。现在我想从数据集中减去平均值。不使用for循环如何实现?
我尝试直接减去X - 平均值但返回错误
`operands could not be broadcast together with shapes (182,108,130) (130,182) `
我希望在每个块中减去平均值。
计算平均值时需要使用
keepdims=True
。示例代码如下:
x = np.random.random((180,108,130)) # random init
x_mean = x.mean(axis=1, keepdims=True) # shape (180, 1, 130)
x - x_mean