1、numpy.random.randint默认包含low、high、size和dtype四个参数。
numpy.random.randint(low,high,size,dtype)
默认参数 high是None,如果只写参数low,那随机生成数的范围为就是[0,low)。默认size为1。
df = np.random.randint(50,size=10)#生成[0,50)的长度为10的一维数组
输出结果为
array([19, 38, 49, 47, 10, 49, 17, 5, 5, 23])
如果规定了high,随机产生数范围就是[low,high)。
df = np.random.randint(1,100,size=20)
print(df)
输出结果为[1,100)的随机长度为20的一维数组。
[62 18 1 50 4 76 38 45 5 13 38 36 38 25 4 32 14 13 53 60]
上述输出结果为一维数组,改变size时可构造多维数组
df = np.random.randint(50,size=(2,3))
结果为[0,50)的2×3矩阵
array([[25, 34, 34], [12, 8, 29]])