【发布时间】:2018-02-15 13:52:28
【问题描述】:
我正在使用 python 进行一些统计分析,但是我是该领域的新手,并且一直遇到错误。
对于背景,我正在为每个样本大小计算一组 sample_means,200 次。然后我计算每个样本大小的平均值和标准偏差,然后将它们存储在数组中。这是我的代码:
in[] =
sample_sizes = np.arange(1,1001,1)
number_of_samples = 200
mean_of_sample_means = []
std_dev_of_sample_means = []
for x in range (number_of_samples):
mean_of_sample_means.append(np.mean(sample_sizes))
std_dev_of_sample_means.append(np.std(sample_sizes))
in[] = # mean and std of 200 means from 200 replications, each of size 10
trials[0], mean_of_sample_means[0], std_dev_of_sample_means[0]
out[] = (10, 500.5, 288.67499025720952)
我现在正在尝试使用以下输入绘制数据:
plt.plot(sample_sizes, mean_of_sample_means);
plt.ylim([0.480,0.520]);
plt.xlabel("sample sizes")
plt.ylabel("mean probability of heads")
plt.title("Mean of sample means over 200 replications");
但是当我这样做时,我得到以下错误:
242 if x.shape[0] != y.shape[0]:
243 raise ValueError("x and y must have same first dimension, but "
--> 244 "have shapes {} and {}".format(x.shape, y.shape))
245 if x.ndim > 2 or y.ndim > 2:
246 raise ValueError("x and y can be no greater than 2-D, but have "
ValueError: x and y must have same first dimension, but have shapes (1000,) and (200,)
对我哪里出错有任何想法吗?我觉得它可能很明显,我没有看到,因为我是新手。任何帮助,将不胜感激!!
【问题讨论】:
-
嗨,您可以尝试将代码编辑为您用来生成
ValueError的实际代码吗?包括所有模块导入和变量定义(例如,trials不存在) -
我也这么认为,但我认为 OP 副本是从笔记本上粘贴的
-
我认为您的
mean_of sample_means将有 500.5 的所有 200 个恒定条目。与std_dev_of_sample_means相同,它将有 288.67499025720952 -
您的
sample_sizes数组是一个在所有 200 次迭代中包含 [1,2,3....1000] 的常量数组。您正在这个常量数组上计算平均值和 std_dev 200 次 not 在这个集合中的随机样本(子集)上。
标签: python python-3.x matplotlib data-science valueerror