Numpy multivariate_normal function generated different values of the same seed in python3.7 and python 3.10 - Stack Overflow

admin2025-05-02  1

Numpy multivariate_normal function generated different values of the same seed in python3.7 and python 3.10. Following is the simple code.

import numpy as np
cov = [[1, 0.6, 0.28, 0.4, 0.4],
 [0.6, 1, 0.35, 0.34, 0.4],
 [0.28, 0.35, 1, 0.4, 0.37],
 [0.4, 0.34, 0.4, 1, 0.3],
 [0.4, 0.4, 0.37, 0.3, 1]]
np.random.seed(97)
rands = np.random.multivariate_normal(mean=[0]*5, cov=cov,
                                      size=2)
print(rands)

With python 3.10.6 and numpy 1.26.3, the result is

array([[1.28283472, 0.61756311, 1.16581242, 1.23132159, 2.03636479],
       [0.50796757, 0.26308658, 1.03859767, 0.70797761, 1.62774376]])

With python 3.7.13 and numpy 1.21.5, the result is

array([[1.0435602 , 1.14090287, 0.76909806, 2.15961647, 1.18447025],
       [0.63861344, 0.53924135, 0.66093208, 1.78844199, 0.47196233]])

I cannot compare with the same numpy version because it will trigger import error of numpy.

So what is the problem here?

转载请注明原文地址:http://www.anycun.com/QandA/1746119317a91935.html