np.random.randint()的用法详解
np.random.randint(low,high=None,size=None,dtype='l')low—–为最小值high—-为最大值size—–为数组维度大小dtype—为数据类型,默认的数据类型是np.int。从一个均匀分布中随机采样,生成一个整数或N维整数数组,取数范围:若high不为None时,取[low,high)之间随机整数,否则取值[0,low)之间随机整数。np.rando
·
np.random.randint(low, high=None, size=None, dtype='l')
low—–为最小值
high—-为最大值
size—–为数组维度大小
dtype—为数据类型,默认的数据类型是np.int。
- 从一个均匀分布中随机采样,生成一个整数或N维整数数组,
- 取数范围:若high不为None时,取[low,high)之间随机整数,否则取值[0,low)之间随机整数。
np.random.randint(1.75, 4, 11) ##11个随机整数数字
#array([3, 3, 2, 3, 1, 1, 2, 2, 2, 3, 2])
np.random.randint(5, size=(2, 4)) #二行四列,higt为none,取值是0到5之间的整数
array([[4, 3, 0, 4],
[3, 1, 1, 3]])
np.random.randint(a,b):用于生成一个指定范围内的整数。其中参数a是下限,参数b是上限,生成的随机数n:a<=n<b,即[a,b)
更多推荐
已为社区贡献15条内容
所有评论(0)