np.random.rand均匀分布随机数和np.random.randn正态分布随机数函数使用方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013555719/article/details/83990006

np.random.rand用法

觉得有用的话,欢迎一起讨论相互学习~Follow Me

生成特定形状下[0,1)下的均匀分布随机数

  • np.random.rand(a1,a2,a3…)生成形状为(a1,a2,a3…),[0,1)之间的 均匀分布 随机数
np.random.rand(3,2)
           array([[ 0.14022471,  0.96360618],  #random
                  [ 0.37601032,  0.25528411],  #random
                  [ 0.49313049,  0.94909878]]) #random

np.random.randn用法

生成特定形状下的正态分布随机数

  • 正态分布高斯分布 np.random.randn(a1,a2,a3…)生成形状为(a1,a2,a3…)的 均匀分布 随机数
  • 如果想要生成满足 N ( μ , σ 2 ) N(\mu, \sigma^2) 其中 μ , σ 2 \mu表示平均值, \sigma^2表示方差 , 可以使用语句sigma * np.random.randn(...) + mu
>>> np.random.randn()
2.1923875335537315 #random

Two-by-four array of samples from N(3, 6.25):

>>> 2.5 * np.random.randn(2, 4) + 3
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],  #random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]]) #random

猜你喜欢

转载自blog.csdn.net/u013555719/article/details/83990006