python的正/负运算符± [英] plus/minus operator for python ±

查看:301
本文介绍了python的正/负运算符±的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在python 2或3中执行加/减运算的方法.我不知道该命令或运算符,也找不到执行该操作的命令或运算符.

I am looking for a way to do a plus/minus operation in python 2 or 3. I do not know the command or operator, and I cannot find a command or operator to do this.

我想念什么吗?

推荐答案

另一种可能性:不确定性是一个模块用于进行误差容限的计算,即

Another possibility: uncertainties is a module for doing calculations with error tolerances, ie

(2.1 +/- 0.05) + (0.6 +/- 0.05)    # => (2.7 +/- 0.1)

将被写为

from uncertainties import ufloat

ufloat(2.1, 0.05) + ufloat(0.6, 0.05)

我得到了一些奇怪的结果,并且在对此进行了更多研究之后,我找出了原因:指定的误差不是公差(如工程蓝图中的硬加性极限),而是一个标准偏差值-这就是上述计算结果的原因

I was getting some odd results, and after a bit more playing with this I figured out why: the specified error is not a tolerance (hard additive limits as in engineering blueprints) but a standard-deviation value - which is why the above calculation results in

ufloat(2.7, 0.07071)    # not 0.1 as I expected!

这篇关于python的正/负运算符±的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆