I'm looking for an efficient way to do an outer sum over a 2d matrix columns.
Let say A is a (2, 3) matrix, my wanted result is shaped (3,2,2) and defined as :
A = np.array([[a11, a12, a13],
[a21, a22, a23]])
myWantedResult = np.array( [[[a11+a11, a11+a21],
[a21+a11, a21+a21]], # This is the np.add.outer(A[:,0],A[:,0])
[[a12+a12, a12+a22 ],
[a22+a12, a22+a22]], # This is the np.add.outer(A[:,1],A[:,1])
[[a13+a13, a13+a23],
[a23+a13, a23+a23]]# This is the np.add.outer(A[:,2],A[:,2])
])
I've already tried to loop over the column but it is quite time-consuming because I want to do it on large array. I'm looking for a vectorized solution.
Many thanks !