使用numpy的random.multivariate_normal函数来实现:import numpy as npdef get_multi_normal_distribution(L): # 将列表L转为numpy数组 L = np.array(L) # 提取均值和标准差 u = L[:, 0] o = L[:, 1] # 计算协方差矩阵 cov = np.diag(o**2) # 生成多元正态分布函数 multi_normal_dist = np.random.multivariate_normal(u, cov) return multi_normal_distL = [(1, 2), (3, 4), (5, 6)]result = get_multi_normal_distribution(L)print(result)
import numpy as np# 定义正态分布函数def normal_distribution(u, o): return np.random.normal(loc=u, scale=o, size=None)# 测试正态分布函数u = 0o = 1x = normal_distribution(u, o)print("均值为{},标准差为{}的正态分布函数生成的随机数为:{}".format(u, o, x))