gpt4 book ai didi

python - 我的方差方程在 Python 中给出了一个疯狂的输出

转载 作者:太空宇宙 更新时间:2023-11-04 07:20:16 25 4
gpt4 key购买 nike

这个程序的重点是在不使用函数的情况下随机获取一个列表并找出该列表的均值和方差。我的方差方程给出了一个小数点后几位的输出。

    variance = (mean - r)**2.0 + variance

我得到的输出示例是 8784462.44,而它应该是 87844.6244。我不知道我的代码出了什么问题。

最佳答案

Variance = (1/n) times (sum of (x - mean(x))^2) -- 你只有总和;你忘了乘以 1/n。

有时方差定义为 (1/(n - 1)) 次(总和 ...)——我不知道您使用的是什么定义。

关于python - 我的方差方程在 Python 中给出了一个疯狂的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21272163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com