Rychly fix:
import math
math.round = lambda num: math.floor(num+0.5)
round sa bude stale spravat ako sa ma, a pribudne math.round na klasicke
aritmeticke zaokruhlovanie.
Jan Janech
azurIt wrote:
taktiez si myslim, ze je to velmi nestastne riesenie, mala sa pre toto vytvorit
nova funkcia. existuje tam aj nieco pre 'klasicke' zaokruhlovanie ?
azur
-----Pôvodná správa-----
Od: Pavel Kosina [mailto:[email protected]]
Komu: Konference PyCZ <[email protected]>
Predmet: Re: [python] round v python 3.0
Děkuji, ale stejně je to zvláštní. Nevím, nakolik se Python používá více
k vědeckým a statistickým výpočtům než na běžnou matematiku. A i kdyby
- tento způsob zaokrouhlování mohl zůstat někde v modulu math nebo
scientific (kdyby existoval). Pokud budeme mít extrémní případ ze samých
čísel 0,5 - 1,5 - 2,5- 3,5- apod tak se chyba horší, protože např. nikdy
nedosáhneme na zaokrouhlení 1 -3 - 5 apod.-.-..... To s Vámi
nepolemizuji, jen přemýšlím nahlas.
--
geon
Pavel Kosina
Stepan Wagner napsal(a), dne 1.2.2009 16:28:
citace ze stranky http://en.wikipedia.org/wiki/Rounding#Round-to-even_method
"""When dealing with large sets of scientific or statistical data,
where trends are important, traditional rounding on average biases the
data upwards slightly. Over a large set of data, or when many
subsequent rounding operations are performed as in digital signal
processing, the round-to-even rule tends to reduce the total rounding
error, with (on average) an equal portion of numbers rounding up as
rounding down. This generally reduces upwards skewing of the
result."""
Stepan
2009/2/1 Pavel Kosina <[email protected]>:
Nevíte někdo, *proč* v Python 3.0 platí:
round(0.5)
0
round (1.5)
2
round (2.5)
2
round (3.5)
4
Jo, máme to napsané v manuálu, že to takhle je
http://docs.python.org/3.0/library/functions.html#round, ale mě zajímá proč
to je takto, a ne podle toho, jak se to učí v 5. třídě, tedy že od pětky
včetně nahoru se zaokrouhluje nahoru vždy, a ne jen někdy .....
Díky
--
geon
Pavel Kosina
_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python
_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python
--
____________________________
Ing. Jan Janech
Katedra softverovych technologii
Fakulta riadenia a informatiky
Zilinska Univerzita
_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python