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.
如果我想实现这个功能:
我知道我可以写一个这样的循环:
result = 0 for i in range(len(x)): for j in range(len(y)): result += x[i] * y[j]
但是如果我想用numpy来完成,我该怎么办呢?
与np.einsum-
np.einsum
np.einsum('i,j->',x,y)
或者简单地求和,然后得到标量的乘积 -
x.sum()*y.sum()
您可以为此使用广播
np.sum(x * y[:, None])