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

numpy的随机数模块

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

numpy的随机数模块

在机器学习中经常会遇到随机数据的生成,但是总是容易弄混,这里做一下总结对于numpy中的随机数生成模块。

函数功能返回值类型
np.random.rand(d0,d1,…,dn)产生元素在(0,1)均匀分布的数组浮点型
np.random.uniform(low,high,size)产生元素在[low,high]均匀分布的数组浮点数
np.random.randint(low,high,size)产生元素在(low,high)均匀分布的整数整数
np.random.randn(d0,d1,…,dn)产生呈标准正态分布的数组浮点数
np.random.normal(mv,std,size)产生呈正态分布的数组浮点数

代码:

import numpy as np

x = np.random.rand(3, 2)
print(x)
print('**'*15)
y = np.random.uniform(-100,100,20)
print(y)
print('**'*15)
a = np.random.randint(-100,100,20)
print(a)
print('**'*15)
b = np.random.randn(2,2,2)
print(b)
print('**'*15)
c = np.random.normal(2,0.5,6)
print(c)

运行结果

[[0.57625727 0.54617987]
 [0.07921413 0.79125039]
 [0.76974222 0.14886053]]
******************************
[ 75.38487896 -53.79125549  88.62105214  63.35055533  50.48705619
  29.51594034 -50.84106033  37.3954892   90.95285229 -51.53446924
 -43.21193046 -26.14729232 -86.96321266  69.83668251  -5.57903342
  -2.6205638  -40.45688946 -45.45254006  12.32097219 -33.75984398]
******************************
[   1   76  -72   40   82   30   33  -27   25    6  -42  -84  -77  -44
  -65   39  -38  -54 -100   12]
******************************
[[[ 0.47601291  0.05191076]
  [-0.31335795  1.55532678]]

 [[ 0.07248383 -0.59444396]
  [-0.76099338 -0.5459049 ]]]
******************************
[2.63077706 1.77712256 2.80524075 1.34858267 1.70068987 1.29810127]



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/968502.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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