随机数种子
RandomState
RandomState exposes a number of methods for generating random numbersdrawn
from a variety of probability distributions.
使用示例
prng = np.random.RandomState(123456789) # 定义局部种子
prng.rand(2, 4)
prng.chisquare(1, size=(2, 2)) # 卡方分布
prng.standard_t(1, size=(2, 3)) # t 分布
prng.poisson(5, size=10) # 泊松分布
random.seed()
random.seed(123456789) # 种子不同,产生的随机数序列也不同,随机数种子都是全局种子
要每次产生随机数相同就要设置种子,相同种子数的Random对象,相同次数生成的随机数字是完全相同的;
random.seed(1)
这样random.randint(0,6, (4,5))每次都产生一样的4*5的随机矩阵
This method is called when RandomState is initialized. It can be called again
to re-seed the generator.
numpy.random模块
linspace(start, end, num):
如linspace(0,1,11)结果为[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1];
arange(n): 产生一个从0到n-1的向量,如arange(4)结果为[0,1,2,3]
简单随机生成数据相关函