#NEWLINE# def multivariate_gaussian( X , mu , Sigma2 ) : #NEWLINE# #INDENT# k = float ( len ( mu ) ) #NEWLINE# X = np . copy ( X ) #NEWLINE# if any ( ( ( s == 1 ) for s in Sigma2 . shape ) ) : #NEWLINE# #INDENT# Sigma2 = np . diag ( Sigma2 . ravel ( ) ) #NEWLINE# #UNINDENT# X -= mu . reshape ( 1 , ( - 1 ) ) #NEWLINE# return ( ( ( ( 2 * np . pi ) ** ( ( - k ) / 2 ) ) * ( det ( Sigma2 ) ** ( - 0.5 ) ) ) * np . exp ( ( ( - 0.5 ) * np . sum ( ( np . dot ( X , pinv ( Sigma2 ) ) * X ) , axis = 1 ) ) ) )