问题
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