0

I am trying to implement multivariate gaussian pdf. I have a strange issue with the ** operator.The code is

def multi_var(x,mu,cov):
   #Multivariate gaussian
   print (1/2*np.pi)**(len(x)/2)
   return(((1/2*np.pi)**(len(x)/2))/np.sqrt(np.abs(np.linalg.det(cov)))*np.exp(np.dot(np.matrix.transpose(x-mu),np.dot(np.linalg.inv(cov),(x-mu)))))

In the command it gives

>>> print multi_var(np.matrix('0;0;4'),np.matrix('0;0;6'),np.matrix([[.3,.67,8],[2,3,8],    [2,.05,2]]))
2
[[ 0.]]

When I execute the same code from command line

>>> x=np.matrix('0;0;4')
>>> print (1/2*np.pi)**(len(x)/2)

I get

 1.96870124322
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
user3443615
  • 155
  • 1
  • 1
  • 9

0 Answers0