矩阵未针对点积对齐

Matrix are not aligned for dot product

这是我的 df 矩阵:

    0   Rooms   Area    Price
0   0   0.4 0.32    0.307692
1   0   0.4 0.40    0.461538
2   0   0.6 0.48    0.615385
3   0   0.6 0.56    0.646154
4   0   0.6 0.60    0.692308
5   0   0.8 0.72    0.769231
6   0   0.8 0.80    0.846154
7   0   1.0 1.00    1.000000

这是我的 B 矩阵:

weights
0   88
1   87
2   44
3   46

当我写 df.dot(B) 时,它说矩阵未对齐。 但是这里 df 是 8*4 矩阵, B4*1 那么它不应该生成一个'8*1矩阵作为点积吗?

errors: ValueError: matrices are not aligned

你可以mul

out = df.mul(B['weights'].values,axis=1)
Out[207]: 
   0  Rooms   Area      Price
0  0   34.8  14.08  14.153832
1  0   34.8  17.60  21.230748
2  0   52.2  21.12  28.307710
3  0   52.2  24.64  29.723084
4  0   52.2  26.40  31.846168
5  0   69.6  31.68  35.384626
6  0   69.6  35.20  38.923084
7  0   87.0  44.00  46.000000

"DataFrame的列名和other的索引必须包含相同的值,"

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.dot.html

尝试重命名 B 的索引以匹配 A 的列名。