loop - 调用一系列索引数据

时间:2017-09-06 02:05:56

标签: python for-loop std stderr

我正在尝试通过NumberFormat.java:2: error: NumberFormat is already defined in this compilation unit import java.text.NumberFormat; ^ NumberFormat.java:10: error: cannot find symbol NumberFormat defaultFormat = NumberFormat.getCurrencyInstance(); ^ symbol: method getCurrencyInstance() location: class NumberFormat NumberFormat.java:11: error: cannot find symbol System.out.println("US: " + defaultFormat.format(num)); ^ symbol: method format(double) location: variable defaultFormat of type NumberFormat 3 errors 索引调用所有US: $1000.32 _ of_sample_means并将其除以各自的std_error来生成std_dev列表,但是我我不确定如何正确调用[i]中的[i^.5]。谢谢!

[i]

2 个答案:

答案 0 :(得分:1)

我希望这就是你要找的:)如果我误解了你的问题,请告诉我

sample_sizes2 = np.arange(1,1001,100)

mean_of_sample_means = []
std_dev_of_sample_means = []
std_errors = []
for i in sample_sizes2:
    probabilities=make_throws(200,i)
    mean_of_sample_means.append(np.mean(probabilities))
    std_dev_of_sample_means.append(np.std(probabilities))
    std_errors.append(std_dev_of_sample_means[-1]/(i**.5)) # previously it was i^.5

print(std_dev_of_sample_means)
print(std_errors)

std_dev_of_sample_means[-1]指的是列表中最后一个元素的值(因为[-1]访问列表中的最后一个值)。在这种情况下,它是您刚刚附加到std_dev_of_sample_means

的值

修改1:将i^.5更改为i**.5。当你想要**将值提升到一个幂时,你正在使用^。 Python将此解释为xor。

答案 1 :(得分:1)

我相信您只想使用enumerate()来获取for-loop

的索引和值
sample_sizes2 = np.arange(1,1001,100)

mean_of_sample_means = []
std_dev_of_sample_means = []
for index,value in enumerate(sample_sizes2):
    probabilities=make_throws(200,value)
    mean_of_sample_means.append(np.mean(probabilities))
    std_dev_of_sample_means.append(np.std(probabilities))
    std_error.append(std_dev_of_sample_means[index]/(value**.5))  *-edit: added append and changed ^ to **

print(std_dev_of_sample_means)
print(std_error)