Plus / minus for python ±

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

Did I miss something?

+5
source share
5 answers

Another possibility: uncertainties is a module for performing calculations with error tolerances, i.e.

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

which will be written as

 from uncertainties import ufloat ufloat(2.1, 0.05) + ufloat(0.6, 0.05) 

Edit: I got some odd results, and after a bit more games with this, I realized why: the error indicated is not a tolerance (hard additive restrictions, as in the technical drawings), but the standard deviation value is why the above calculation leads to

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

If you use matplotlib, you can print math expressions similar to Latex. For the +/- character, you should use:

 print( r"value $\pm$ error" ) 

Where r converts the string to raw format, and $ signs are around the part of the string, which is a mathematical equation. Any words that are in this part will have a different font and will not have spaces between them, unless explicitly indicated with the correct code. This can be found on the relaent matplotlib documentation page .

Sorry if this is too niche, but I came across this question, trying to find the next answer.

+3
source

I think you want for this equation:

enter image description here

Well, there’s no operator for this, unless you are using SymPy , only you can do it do the if and find each factor.

+2
source

There is no such object in SymPy yet (as you saw, there is a problem with the suggestion https://github.com/sympy/sympy/issues/5305 ). However, it is not easy to imitate. Just create a Symbol and change it to +1 and -1 separately at the end. how

 pm = Symbol(u'±') # The u is not needed in Python 3. I used ± just for pretty printing purposes. It has no special meaning. expr = 1 + pm*x # Or whatever # Do some stuff exprpos = expr.subs(pm, 1) exprneg = expr.subs(pm, -1) 

You can also simply track two equations from the start.

+1
source

Instead of evaluating type expressions

 s1 = sqrt((125.0 + 10.0*sqrt(19)) / 366.0) s2 = sqrt((125.0 - 10.0*sqrt(19)) / 366.0) 

you can use

 pm = numpy.array([+1, -1]) s1, s2 = sqrt((125.0 + pm * 10.0*sqrt(19)) / 366.0) 
0
source

Source: https://habr.com/ru/post/1210778/


All Articles