TypeError: 1D weights expected when shapes of a and weights differ.
我百思不得其解,于是查看官方解释
numpy.average(a, axis=None, weights=None, returned=False)
里面的weights是这样描述的
weights : array_like, optional
An array of weights associated with the values in a. Each value ina contributes to the average according to its associated weight.The weights array can either be 1-D (in which case its length must bethe size of a along the given axis) or of the same shape as a.If weights=None, then all data in a are assumed to have aweight equal to one.
与a中的值相关联的一组权重。ina中的每个值根据其关联的权重对平均值做出贡献。权值数组可以是一维的(在这种情况下,它的长度必须是沿给定轴的a的大小),也可以是与a相同的形状。如果权值为None,则假设a中的所有数据的权值都为1。
但是我的W就是和a一样的维度啊。
终于,在询问了大佬后才知道