python的加/减运算符± [英] plus/minus operator for 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.
我错过了什么吗?
推荐答案
另一种可能性:uncertainties 是一个模块用于进行容错计算,即
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屋!