numpy.random函数应用(持续更新)

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]])

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值