在另一列中使用随机抽取的标记创建采样分布

2024-06-17 10:22:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力解决这个问题

Create a sampling distribution for our 30-observation-mean estimator of the mean of C. To do so, randomly draw 1000 sets of 30 observations from C, using the randomly drawn indices in D (the first row are first 30 randomly-drawn indexes, the second row are the second 30 randomly-drawn indexes, etc). For each random draw, compute the mean. Then plot the histogram of the distribution. Compare the distribution to np.mean(C).

C在哪里

array([23, 23, 23, ..., 68, 34, 42])

C的大小为100030,D列的大小为(大小为30000

array([[23989, 10991, 81533, ..., 75050, 13817, 47678],
       [54864, 54830, 89396, ..., 22709, 14556, 62298],
       [ 2936, 28729,  4404, ..., 21431, 81187, 49178],
       ...,
       [30737, 12974, 41031, ..., 43003, 61132, 33385],
       [64713, 53207, 49529, ..., 72596, 76406, 15207],
       [29503, 71648, 27210, ..., 31298, 47102, 13024]])

我试图理解这里的问题以及如何解决它。到目前为止,我所做的是初始化一个带零的列表,并尝试根据D中的索引获取平均值。但我不确定这是否是实际要求的?有什么帮助吗

 samp = np.zeros( (1000, 1))
    for i in np.arrange(0, 1000):
       samp(i) = np.mean(C( D(i,)))

另外,这是从C中随机抽取样本,但不确定如何向其中添加D索引

means_size_30 = []
for x in range(1000):
    mean = np.random.choice(C, size = 30).mean()
    means_size_30.append(mean)
means_size_30 = np.array(means_size_30)
plt.hist(means_size_30);

Tags: oftheinforsizenpmeanrandomly
1条回答
网友
1楼 · 发布于 2024-06-17 10:22:18

您可以使用D中提供的索引直接访问C的值。 如果使用二维数组D访问一维数组C的值,则生成的数组将具有与D相同的形状:二维。它将有1000行,每行有来自C的30个样本

在下一步中,您只需计算每行的平均值(设置轴=1):

means_size_30 = C[D].mean(axis=1)
plt.hist(means_size_30)
plt.axvline(np.mean(C))

相关问题 更多 >