Well, knowing that each Maxwell is distribution of the absolute value of the molecule velocity, where each component is normally distributed, you could make sampling like code belowimport numpy as npimport matplotlib.pyplot as pltfrom scipy.stats import maxwelldef maxw(size = None): """Generates size samples of maxwell""" vx = np.random.normal(size=size) vy = np.random.normal(size=size) vz = np.random.normal(size=size) return np.sqrt(vx*vx + vy*vy + vz*vz)mdata = maxw(100000)h, bins = np.histogram(mdata, bins = 101, range=(0.0, 10.0))x = np.linspace(0.0, 10.0, 100)rv = maxwell()fig, ax = plt.subplots(1, 1)ax.hist(mdata, bins = bins, density=True)ax.plot(x, rv.pdf(x), 'k-', lw=2, label='Maxwell pdf')plt.title("Maxwell")plt.show()这是采样与Maxwell PDF重叠的图片And here is the picture with sampling and Maxwell PDF overlapped 这篇关于Python从正态分布生成随机的Maxwell分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-21 12:56