1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 #sigma
for i in range(Nclasses):
sigma_temp = np.zeros((Ndims))
#Collect vectors from class k
for j in range(Npts):
if labels[j] == classes[i]:
x = X[j,:]
#Subtract mu
x = x  mu[i,:]
#Square each element individually
x = np.square(x)
#Sum over vectors to gain a single vector
sigma_temp += x
#Divide by number of vectors in k
sigma_temp /= N_k[i]
#Convert to a diagonal matrix
sigma[i,:,:] = np.diag(sigma_temp)
