math - Python division -
I was trying to normalize the number from -100 to 0 to 10 to 100 and only problems were To note that there are no variables here, it does not evaluate the way I expect it to be:
gt; & Gt; (20-10) / (100-10) 0 Float division does not work either:
& gt; & Gt; & Gt; If it is inserted on a float on either side of the partition, it will work: & gt; & Gt; & Gt; (20-10) / float ((100-10)) 0.1111111111111111 In the first example, each side is evaluating as an int, which means that the final answer will be inserted int . Since 0.111 is less than 5, this is the circumference of 0. This is not transparent in my opinion, but I think that's such a way.
What is the explanation?
You are using Python 2.x, where the integer division instead of being a floating point number Will be reduced.
& gt; & Gt; & Gt; 1/2 0 You get one of them float : gt; & Gt; & Gt; Float (10 - 20) / (100 - 10) -0.1111111111111111 or __future__ from the import partition , the force / To adopt the behavior of 3.x which always gives a float. gt; & Gt; __future__ by Import Split & gt; & Gt; & Gt; (10 - 20) / (100 - 10) -0.1111111111111111
Comments
Post a Comment