栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

numpy里random的使用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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.randint(1,5,size=(2,3))
    array([[2, 4, 2],
       [2, 2, 3]])
    
  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]])
    
暑期编程PK赛 得CSDN机械键盘等精美礼品!
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1015614.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号