Python | Numpy method np.multivariate_normal ()



Using the np.multivariate_normal() method, we can get an array of multivariate normal values ​​using np.multivariate_normal () .

Syntax: np.multivariate_normal (mean, matrix, size)
Return: Return the array of multivariate normal values.

Example # 1:
In this example we can see that using np.multivariate_normal () we can get an array of multivariate normal values ​​using this method.

# NumPy import

import numpy as np

  

mean = [ 1 , 2 ]

matrix = [[[ 5 , 0 ], [ 0 , 5 ]]

# using the np.multinomial () method

gfg = np.random.multivariate_normal (mean, matrix, 10 )

 

print (gfg)

Output:

[[6.24847794 6.57894103]
[1.24114594 3.22013831]
[3.0660329 2.1442572]
[0.3239289 2.79949784]
[-1.42964186 1.11846394]
[-0.08521476 0.74518872]
[1.42307847 3.27995017]
[3.08412374 0.45869097]
[2.2158498 2.97014443]
[1.77583875 0.57446964]]

Example # 2:

# NumPy import

import numpy as np

  

mean = [ 0 , 0 , 0 ]

matrix = [[ 1 , 0 , 0 ], [ 0 , 1 , 0 ], [ 0 , 0 , 1 ]]

# using the np.multinomial () method

gfg = np.random.multivariate_normal (mean, matrix, 5 )

 

print (gfg)

Output:

[[-2.21792571 -1.04526811 -0.4586839]
[0.15760965 0.83934119 -0.52943583]
[-0.9978205 0.79594411 -0.00937]
[-0.16882821 0.1727549 0.14002367]
[-1.34406079 1.03498375 0.17620708]]