外部产品所有维度上的总和 [英] Numpy sum over all dimension of the outer product
本文介绍了外部产品所有维度上的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我要实现此功能:
If I want to implement this function:
我知道我可以编写这样的循环:
I know I can write a loop like this:
result = 0
for i in range(len(x)):
for j in range(len(y)):
result += x[i] * y[j]
但是,如果我想使用numpy来完成该怎么办?
But what if I want to use numpy to complete, how can I do?
推荐答案
Or simply sum-reduce and then get product of the scalars -
x.sum()*y.sum()
这篇关于外部产品所有维度上的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文