np.random.randint(lowhigh=Nonesize=Nonedtype='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)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐