首页 > 解决方案 > numpy.std 与 pythons statistics.stdev ,浮点精度

问题描述

有人可以向我解释为什么 python 包确实产生标准偏差的确切值而 numpy 没有?Python_ss在其source_code中使用该函数来计算残差平方和。似乎减法确实产生了零。numpy 文档指出,根据输入数据的精度,结果可能不准确

为什么在这里 python 比 numpy 更准确?

import statistics
import numpy as np
a = 3.28*np.ones(100)
print(f'STD with numpy {np.std(a)}')
print(f'STD with pythons statistics package {statistics.stdev(a)}')

STD with numpy 4.440892098500626e-16
STD with pythons statistics package 0.0

标签: pythonnumpy

解决方案


推荐阅读