本文的主要内容是基于中国大学mooc(慕课)中的“Python数据分析与可视化”课程进行整理和总结。
np.random的随机数函数
numpy的random子库可以为数组提供随机数的相关功能,书写格式为mp.random.*(*为函数名城)下面介绍几个基本的随机数函数。
rand(d0,d1,…,dn):根据d0-dn创建随机数数组,浮点数,(0,1),均匀分布;
randn(d0,d1,…,dn):根据d0-dn创建随机数数组,标准正态分布;
randint(low,high,shape):根据shape创建随机正数或正数数组,范围是[low,high);
seed(s):随机数种子,s是给定的种子数;
示例:
a = np.random.rand(3,4,5)
a
array([[[0.97017019, 0.3527823 , 0.60624838, 0.52925984, 0.44141665],
[0.56680268, 0.38601911, 0.43663509, 0.13782552, 0.7726391 ],
[0.5881991 , 0.29901631, 0.18105188, 0.21032785, 0.64600204],
[0.66994449, 0.28860224, 0.67514971, 0.33213358, 0.18316808]],
[[0.44588405, 0.48113294, 0.