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

Python中Numpy库np.random模块函数总结

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

Python中Numpy库np.random模块函数总结

import numpy as np

1.np.random.random : 生成0到1之间的随机数

import numpy as np

nd1 = np.random.random([3,3])    # 生成一个3行3列范围在0到1之间的随机数矩阵

print(nd1)


"""
>>>array([[0.90347813, 0.33751045, 0.83560751],
       [0.91226884, 0.29418309, 0.53015394],
       [0.10795564, 0.52470976, 0.60163383]])
"""

2.np.random.randn : 生成标准正态分布的随机数

import numpy as np

nd2 = np.random.randn(2,3)  #生成2行3列的标准正态分布随机数

print(nd2)

"""
>>>array([[ 1.98694352, -1.67930434,  1.0705832 ],
       [-0.09444916, -0.65653559,  0.3868352 ]])
"""

3.np.random.randint : 生成随机的整数

import numpy as np

nd3 = np.random.randint(start=1,end=6) # 随机在start到end之间的整数(左闭右开)

print(nd3)

"""
>>>2
"""

4.np.random.normal : 生成正态分布的数

5.np.random.uniform : 生成均匀分布的随机数

6.np.random.seed : 设置随机数种子

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

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

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