参考链接: Python中的numpy.random.randn
numpy.random.rand(m,n,p,q…) 生成0到1之间的n个随机数,参数是shape
#传入单个参数
import numpy as np
data=np.random.rand(3)
print(data)
输出:
[0.42487743 0.92537519 0.53686567]
#传入两个参数:输出一个值在0-1之间的三行四列数组
import numpy as np
data=np.random.rand(3,4)
print(data)
输出:
[[0.98377973 0.85092775 0.7504745 0.14616559]
[0.82135553 0.47096988 0.43921536 0.52325622]
[0.25834071 0.3646412 0.88872318 0.24679017]]
numpy.random.randn(d0,d1,d2)从标准正态分布中返回一个或多个样本,参数是shape
import numpy
data=numpy.random.randn(3,4)
print(data)
输出:
[[-1.00371958 1.47718184 0.70418891 0.84347875]
[-0.34671091 1.20209922 -1.49002216 1.58234722]
[-0.05994912 0.08149479 -1.10874929 -0.88186209]]
numpy.random.randint(m,n,size)([m,n))左闭右开
import numpy
data=numpy.random.randint(1,100,[3,4])
print(data)
输出:
[[ 8 41 51 46]
[94 5 7 55]
[86 89 53 65]]
#生成1-100之间一个三行四列的随机数组
numpy.random.random_integers(m,n,size)([m,n]) 双闭 整形
import numpy
data=numpy.random.random_integers(1,100,[3,4])
print(data)
输出:
[[85 31 90 8]
[ 2 51 14 6]
[73 40 54 65]]
numpy.random.random_sample([size]) 生成(0,1]之前size的数组:
import numpy
data=numpy.random.random_sample(10)
print(data)
输出:
[0.78198435 0.78581722 0.70935454 0.48435389 0.34285546 0.44082393
0.28817718 0.52779338 0.91154455 0.20794619]
numpy.random.random([size]) 生成(0,1]之前size的数组
import numpy
data=numpy.random.random([2,3])
print(data)
输出:
[[0.39636875 0.59884829 0.64481502]
[0.98957148 0.82963862 0.05764939]]
numpy.random.choice(a, size=None, replace=True, p=None): 从给定的序列中任取一定size的值 a:一维数组 replace:表示已去的是否可重复,默认True P:一维数组,指随机选择时a中各值出现的概率,p内值和为1
import numpy
data=numpy.random.choice([2,3,4,5,6,7],3,False,(0.1,0.2,0.3,0.4,0,0))
print(data)
输出:
[3 5 4]