使用另一列中随机抽取的索引创建抽样分布 Python
Create sampling distribution using randomly drawn indicies in another column 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);
您可以通过D中提供的索引直接访问C的值。
如果使用二维数组 D 访问一维数组 C 的值,则生成的数组将具有与 D 相同的形状:二维。它将有 1000 行,每行有 30 个来自 C 的样本。
在下一步中,您只需计算每一行的平均值(设置轴 =1):
means_size_30 = C[D].mean(axis=1)
plt.hist(means_size_30)
plt.axvline(np.mean(C))
我正在尝试解决这个问题
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);
您可以通过D中提供的索引直接访问C的值。 如果使用二维数组 D 访问一维数组 C 的值,则生成的数组将具有与 D 相同的形状:二维。它将有 1000 行,每行有 30 个来自 C 的样本。
在下一步中,您只需计算每一行的平均值(设置轴 =1):
means_size_30 = C[D].mean(axis=1)
plt.hist(means_size_30)
plt.axvline(np.mean(C))