It seems like np.einsum should do the trick, but I haven’t been able to make it work.
a = np.arange(3) b = np.arange(2) #that computes the outer product res = np.einsum('i,j->ij',a,b) #The resulting array I am looking for is: out = [[0, 1], [1, 2], [2, 3]] #or its transpose.
I’ve been searching and all functions seem to point towards outer product, not outer sum. A
for loop would do the job, but I’d like to have something a lot more efficient than that.
Does anyone know how to implement the outer sum using
np.einsum or something else?
res = np.add.outer(a, b)