Given the following arrays:
X = np.array([[1, 27, 3], [4, -1, 6]])
W = np.array([2, 4, 3])
These two equations are equivalent:
sum_a = 0
for l in range(len(X)):
sum_a += np.sum(W * X[l]) # 141
sum_b = np.sum(np.sum(W * X)) # 141
But these two are not:
sum_a = 0
for l in range(len(X)):
sum_a += np.exp(np.sum(W * X[l])) # 4.797813327299302e+51
sum_b = np.sum(np.exp(np.sum(W * X))) # 1.7199742630376623e+61
Why is that, and how can I make sum_b equivalent to sum_a for the second case? I specifically want to equate the sum using numpy so I can vectorize a bigger equation.