2
用numpy
生成一个正态分布的整数集合的最佳方法是什么?我知道我能得到花车像这样的东西:numpy,如何生成一个正态分布的整数集合
In [31]: import numpy as np
In [32]: import matplotlib.pyplot as plt
In [33]: plt.hist(np.random.normal(250, 1, 100))
Out[33]:
(array([ 2., 5., 9., 10., 19., 21., 13., 10., 6., 5.]),
array([ 247.52972483, 247.9913017 , 248.45287858, 248.91445546,
249.37603233, 249.83760921, 250.29918608, 250.76076296,
251.22233984, 251.68391671, 252.14549359]),
<a list of 10 Patch objects>)
除非你真的需要高精度,我只想一轮浮点数。 – Evert
好的,就像这样:'np.random.normal(250,1,100).round(0)'? – tbc
如果你需要实际的整数:'np.random.normal(250,1,100).round()。astype(np.int)'。 (0是'np.round'的默认值,btw。) – Evert