Numpy学习—np.random.randn()、np.random.rand()和np.random.randint()

版权声明:作者:小白 https://blog.csdn.net/weixin_43687366/article/details/89258501
具体请参考https://blog.csdn.net/zenghaitao0128/article/details/78556535
         https://www.cnblogs.com/hezhiyao/p/8065528.html
numpy.random.rand():的随机样本位于[0, 1)之间。
numpy.random.randn():是从标准正态分布中返回一个或多个样本值。这里的范围就是()
import numpy as np

arr1 = np.random.rand()
print(arr1)

arr2 = np.random.rand(100)
print(arr2)

arr3 = np.random.randn(100)
print(arr3)

arr4 = np.random.randn(2,4)
print(arr4)

a = np.random.randint(1,20,size=(4,4),dtype='uint8')
print(a)
D:\python北风\venv\Scripts\python.exe D:/python北风/numpy知识/rand&randn.py
0.0479076176680423
[0.87837291 0.07926367 0.65228319 0.74214615 0.31661571 0.89140242
 0.05047662 0.9253252  0.07251961 0.52202533 0.50888427 0.37820921
 0.04236712 0.46426376 0.53527316 0.58262449 0.61006648 0.49541628
 0.43751286 0.63990954 0.9493651  0.81081876 0.86252489 0.63378123
 0.85045014 0.34305455 0.95988395 0.81430687 0.04737932 0.89658439
 0.20494303 0.6576473  0.17954643 0.9222191  0.85664036 0.82701783
 0.08395999 0.68592725 0.282314   0.01353303 0.67548876 0.315665
 0.48156132 0.53915318 0.30430808 0.24890889 0.10561204 0.70063686
 0.25957781 0.80885657 0.12388954 0.82421561 0.07006289 0.17652435
 0.59553379 0.07637348 0.93409698 0.42555354 0.53145922 0.71552662
 0.97351334 0.59782855 0.69139816 0.96967609 0.61883166 0.17801031
 0.41158341 0.58421903 0.34617367 0.90771563 0.56460392 0.2129191
 0.7745671  0.86280663 0.29979984 0.40010941 0.21837734 0.84418573
 0.43121147 0.59969753 0.5830628  0.02316962 0.34081256 0.82783402
 0.01218603 0.33755025 0.24113006 0.8289726  0.57715362 0.73419066
 0.59747727 0.16836938 0.51082972 0.05404864 0.00199209 0.86954128
 0.4267199  0.58042238 0.846229   0.33156209]
[ 1.33561869 -0.51063063 -0.59563199  1.25852382  0.23896024  0.75628845
  1.55630362 -1.03172239  0.433224    0.39148338  0.91128565  0.54640966
  1.14936728  1.17457711 -0.81296807  1.45822674 -1.0692011  -0.60329903
  1.35563171 -0.27272956  0.89339747 -0.06241945 -1.42203569 -1.14131527
  1.00443776 -0.4491623  -0.39742472 -0.3835911   1.80797303  1.76542415
 -1.02412211  1.17747793 -1.04203081 -0.41387708  1.5886436   0.55311169
 -0.42442562 -0.57881306  0.21956656  1.10407211 -1.58014147  0.15370797
  0.86177973 -0.50659637  0.02649642  2.03501869  1.62726556 -0.24300252
  1.19767725 -0.27260052 -0.99379173  0.84603997 -1.12920113  0.09168563
 -1.17901478 -0.7227298   0.07387924 -0.18452718  1.17423448 -0.38513804
 -0.26402127  0.42014553 -0.6317797  -0.41556312 -0.92567353  1.04935611
 -0.09881773 -0.50814096  0.88119307 -2.19594063  1.04570995 -1.08911147
 -0.3450531   1.18488096  0.9312479  -0.13665565 -0.27044031 -0.64418195
  0.87648905 -1.05162986  0.45551934 -0.53468467 -0.89227476  1.26401226
 -0.31181943  0.17022567 -1.70523099  0.99135907  0.62171189 -0.44967944
  0.32577803  0.37729966  1.85502769 -0.36937509 -1.78293138  2.13513423
  0.12735647 -0.64478542  0.39379421 -0.0581531 ]
[[-2.16338208  0.85754668  0.49613056 -0.06990232]
 [ 1.39638219 -0.53690093 -1.51991701  1.32181066]]
[[17 10 16  2]
 [ 8 19  5  5]
 [ 5  1 13 17]
 [19 12  5 12]]

猜你喜欢

转载自blog.csdn.net/weixin_43687366/article/details/89258501