python - 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
解决方案
推荐阅读
- php - Cakephp 按条件选择递归关联字段
- c# - 这是什么类型的关系,应该如何配置?
- javascript - 如何在 tensorflow.js 中使用现有的 keras 模型
- google-api - 我的应用是否需要验证才能使用 Gmail API?
- windows - 为什么 Windows 使用 UTF-16LE?
- azure-functions - 是否可以在运行时在 Azure 函数中设置 AppInsights 检测密钥
- flutter - 如何从后台运行的应用程序中监听所有全局按键事件?
- python - 给定列表中的 Python 匹配字典
- apache-spark - 使用 python 可执行文件而不是 spark-submit 提交 Spark 作业
- apache-spark - 在pyspark中使用array_zip进行groupby和collect_list时保留列名