For the method estimate_gaussian, I know it is better to implemented in a vectorized manner by using np.sum() with axis = 0 parameter.
However, I just wanna check is my logic correct when having 2 nested for loops
mu = np.zeros(n)
var = np.zeros(n)
for i in range(n):
sum1 = 0
for j in range(m):
sum1 += X[i][j]
mu[i] = sum1 / m
sum2 = 0
for j in range(m):
sum2 += (X[i][j] - mu[i]) **2
var[i] = sum2 / m
When I run the above code, it throws an IndexError: index 2 is out of bounds for axis 0 with size 2
I am quite confused.
Could anyone help to explain why there is that index error?
Thanks in advance!