Kahan求和:
def KahanSum(data):
s = 0.0
c = 0.0
for i in range(len(data)):
y = data[i] - c
t = s + y
c = (t - s) - y
s = t
return s
本文介绍了一种改进的求和算法——Kahan求和算法,该算法通过引入补偿项来减少浮点运算误差,提高数值稳定性。文章通过具体代码示例展示了Kahan求和算法的实现方式。
Kahan求和:
def KahanSum(data):
s = 0.0
c = 0.0
for i in range(len(data)):
y = data[i] - c
t = s + y
c = (t - s) - y
s = t
return s
转载于:https://my.oschina.net/vazor/blog/114281
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
764

被折叠的 条评论
为什么被折叠?