Looking to make the this calculation as quickly as possible. I have X as n x m numpy array. I want to define Y to be the following:
Y_11 = 1 / (exp(X_11-X_11) + exp(X_11-X_12) + ... exp(X_11 - X_1N) ).
or for Y_00
1/np.sum(np.exp(X[0,0]-X[0,:]))
So basically, Y is also n x m where the i,j element is the 1 / sum_j' exp(X_ij - X_ij')
Any tips would be great! Thanks.
Sample code as requested:
np.random.seed(111)
J,K = 110,120
X = np.random.rand(J,K)
Y = np.zeros((J,K))
for j in range(J):
for k in range(K):
Y[j,k] = 1/np.sum(np.exp(X[j,k]-X[j,:]))
# note each row will sum to 1 under this operation
np.sum(Y,axis=1)