python - 计算数组的第三个标准偏差

标签 python numpy standard-deviation

比如说,我有一个数组:

import numpy as np

x = np.array([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])

如何计算它的第 3 个标准差,以便得到 +3sigma 的值,如下图所示?

enter image description here

通常,我使用 std = np.std(x),但老实说,我不知道它返回的是 1sigma 值还是 2sigma,或其他。我会非常感谢你的帮助。提前谢谢你。

最佳答案

NumPy 的 std 产生标准差,通常用“sigma”表示。要获得 2-sigma 或 3-sigma 范围,您可以简单地将 sigma 乘以 2 或 3:

print [x.mean() - 3 * x.std(), x.mean() + 3 * x.std()]

输出:

[-27.545797458510656, 52.315028227741429]

有关更详细的信息,您可以引用文档,其中指出:

The standard deviation is the square root of the average of the squared deviations from the mean, i.e., std = sqrt(mean(abs(x - x.mean())**2)).

http://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html

关于python - 计算数组的第三个标准偏差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28699342/

相关文章:

python - Nodejs服务器,使用Ajax在html客户端中从Python获取JSON数据

python - 如何将变量放入列表切片操作中?

python - 如何在 Python 中实现 Softmax 函数

python - 如何隔离偏离均值 2 和 3 sigma 的数据,然后在 python 中将它们标记在图中?

java - 蒙特卡罗标准差方程

python - 在 python 中,如何通过用户输入模块名称的字符串来导入模块

python - 将字符串从 Python3 转换为字典

python - 未使用 Python/Basemap 在图形上绘制的线条

python - 按列就地排序在切片上失败

python - 列表元素的代数运算