Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个 ndarrayA和B,一个有形状(4,),另一个(4,1).
A
B
(4,)
(4,1)
当我想使用this计算余弦距离时,它会引发一些抱怨这两个对象的异常are not aligned
are not aligned
有人对此有想法吗?谢谢!
一个是一维数组,另一个是二维数组。
例子:
>>> import numpy as np >>> a = np.arange(4).reshape(4,1) >>> a array([[0], [1], [2], [3]]) >>> a.ravel() array([0, 1, 2, 3]) >>> a.squeeze() array([0, 1, 2, 3]) >>> a[:,0] array([0, 1, 2, 3]) >>> >>> a[:,0].shape (4,)