【发布时间】:2021-06-15 23:18:21
【问题描述】:
我正在使用两种不同的方法来尝试生成引导样本
np.random.seed(335)
y=np.random.normal(0,1,5)
b=np.empty(len(y)) #initializes an empty vector
for j in range(len(y)):
a = np.random.randint(1,len(y)) #Draws a random integer from 1 to n, where n is our sample size
b[j] = y[a-1] #indicies in python start at zero, the worst part of Python in my opinion
c = np.random.choice(y, size=5)
print(b)
print(c)
对于我的输出,我得到不同的结果
[1.04749432 1.71963433 1.71963433 1.71963433 1.71963433]
[-0.25224454 -0.25224454 0.46604474 1.71963433 0.46604474]
我认为答案与随机数生成器有关,但我对确切原因感到困惑。
【问题讨论】:
标签: python numpy random statistics seed