numpy einsum()可以执行外部加法吗? [英] Can numpy einsum() perform outer addition?

查看:42
本文介绍了numpy einsum()可以执行外部加法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在numpy中,我们可以在两个向量 a b 之间执行外加",如下所示:

In numpy, we can perform "outer addition" between two vectors a and b like this:

a=np.c_[1,2,3]
b=np.c_[4,5,6]
result=a+b.T # alternatively this can be a.T+b

是否可以使用 einsum 进行相同的计算?还有其他快速的选择吗?如果 a 等于 b 呢?

Is it possible to use einsum to make the same calculation? Any other fast alternatives? How about if a equals b?

推荐答案

此操作的另一个快速替代方法是使用:

Another fast alternative to this operation is to use:

np.add.outer(a,b)

这篇关于numpy einsum()可以执行外部加法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆