Python:numpy中random使用

=============random.randint的使用=======================

from numpy import random as pp
x,y=pp.randint(0,10,size=(2,4))
print(x)
print(y)

注:指定生成随机数的范围和生成随机数组的大小形式

运行结果:

[8 1 6 8]
[7 8 7 6]

from numpy import random as pp
x,y,z=pp.randint(0,10,size=(3,4))
print(x)
print(y)
print(z)

运行结果:

[1 8 4 0]
[8 5 4 0]
[9 5 2 2]

===============需要对比一下=================

import numpy as np
a,b,c=np.random.random((3,3))
print(a)
print(b)
print(c)
生成的是小数多维数组

[ 0.91553294  0.7210993   0.91108758]
[ 0.3674479   0.41005686  0.76995569]
[ 0.59584865  0.69899946  0.86537229]

import numpy as np
a,b,c=np.random.random(0,1,(3,3))
print(a)
print(b)
print(c)
这样运行出错

================请跟第一节代码比较=========================

import numpy as np
a,b,c=np.random.randint(0,10,size=[3,3])  #《-----()变为【】,照样运行
print(a)
print(b)
print(c)

请跟第一段代码比较。

======================================











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DeniuHe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值