Can numpy einsum() perform outer addition?

∥☆過路亽.° 提交于 2021-02-08 13:49:17

问题


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

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


回答1:


Another fast alternative to this operation is to use:

np.add.outer(a,b)


来源:https://stackoverflow.com/questions/17602796/can-numpy-einsum-perform-outer-addition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!