numpy里random的使用

numpy里random的使用

几个常用方法的使用:

  1. np.random.rand() --> 生成指定维度的的[0,1)范围之间的随机数,输入参数为维度
np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  #random
       [ 0.37601032,  0.25528411],  #random
       [ 0.49313049,  0.94909878]]) #random
  1. np.random.randn() --> 生成指定维度的服从标准正态分布的随机数,输入参数为维度
np.random.randn(2,4)
array([[ 0.56537426, -0.11111651,  1.19069096, -1.14131946],
       [-0.66872042,  0.28158519,  1.16933548, -0.74793281]])
  1. np.random.randint(low, high = None, size = None,dtype = ‘l’)–> 返回随机数或者随机数组成的array
    输入参数有:

    low,high(范围区间为[low,high)),low不可以>=high
    size,
    dtype(默认为int)

    np.random.randint(1,5,size=(2,3))
    array([[2, 4, 2],
       [2, 2, 3]])
    
  2. np.random.random(size = (2,2))–>生成随机浮点数阵列

    np.random.random(size = (2,2))
    array([[0.0215217 , 0.20079832],
       [0.85915167, 0.71522156]])
    
  3. np.random.uniform(2,5,(2,3)) --> 生成范围内的随机小数

    np.round(np.random.uniform(2,5,(4,4)),2)
    array([[4.19, 4.77, 3.76, 3.12],
       [3.97, 4.11, 2.73, 2.4 ],
       [3.65, 2.73, 3.8 , 3.8 ],
       [4.92, 4.04, 4.04, 4.86]])
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值