## Use of random function in Python numpy

#### np.random: generation of random numbers

• ##### np.random.random()
``````import numpy as np
c = np.random.random() #生成一个(0,1)之间的随机浮点数
print('c的值：',c)
``````

• ##### np.random.random(size)
``````import numpy as np
c = np.random.random(5) #生成size个(0,1)之间的随机浮点数
print('c的值：',c)
``````

• ##### np.random.random([m,n]) or np.random.random((m,n))
``````import numpy as np
c = np.random.random([2,6]) #生成m行n列的(0,1)之间的随机浮点数
print('c的值：')
print(c)
``````

• ##### np.random.rand(m,n)
• It has the same function as np.random.random((m,n)), but the parameter form is different.
``````import numpy as np
c = np.random.rand(2,6) #生成m行n列的(0,1)之间的随机浮点数
print('c的值：')
print(c)
``````

• ##### np.random.randint(a,b,size)
``````import numpy as np
c = np.random.randint(0,2,2) #生成size个[a,b)之间的随机整数
print('c的值：')
print(c)
``````

• ##### np.random.uniform(a,b,size)
``````import numpy as np
c = np.random.uniform(0,1,2) #生成size个[a,b)之间的随机浮点数
print('c的值：')
print(c)
``````

• ##### np.random.normal(): The mean is 0, the standard deviation is 1 [no parameter default value]
``````import numpy as np
c = np.random.normal() #生成一个随机浮点数，随机概率与均值为0,标准差为1的正态分布一致【无参默认值】
print('c的值：')
print(c)
``````

• ##### np.random.normal(a,b)
``````import numpy as np
c = np.random.normal(0,1) #生成一个随机浮点数，随机概率与均值为a,标准差为b的正态分布一致
print('c的值：')
print(c)
``````

• ##### np.random.normal(a,b,size)
``````import numpy as np
c = np.random.normal(0,1,2) #生成size个随机浮点数，随机概率与均值为a,标准差为b的正态分布一致
print('c的值：')
print(c)
``````

The above normal distribution formula is reproduced in https://zhidao.baidu.com/question/431881117.html

### Guess you like

Origin blog.csdn.net/weixin_45251017/article/details/124570719
Recommended
Ranking
Daily