runden around round

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Sirius
User
Beiträge: 5
Registriert: Montag 19. Oktober 2009, 14:07

Hallo, ich möchte einen array runden.
Nur kommt da etwas komisches raus

Wie es sein muss, gibt round(0.5)
1

komischerweise gibt around(arange(0,1,0.1))
[ 0. 0. 0. 0. 0. 0. 1. 1. 1. 1.]

also von 0.5 rundet er ab auf 0. Wo liegt das Problem? Wie kann ich es beheben?
Im Internet finde ich leider nur schlechte Angaben zum Befehl around, oder ähnlichen.
Benutzeravatar
jbs
User
Beiträge: 953
Registriert: Mittwoch 24. Juni 2009, 13:13
Wohnort: Postdam

Aus numpy:
Notes
-----
For values exactly halfway between rounded decimal values, Numpy
rounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0,
-0.5 and 0.5 round to 0.0, etc. Results may also be surprising due
to the inexact representation of decimal fractions in the IEEE
floating point standard [1]_ and errors introduced when scaling
by powers of ten.
[url=http://wiki.python-forum.de/PEP%208%20%28%C3%9Cbersetzung%29]PEP 8[/url] - Quak!
[url=http://tutorial.pocoo.org/index.html]Tutorial in Deutsch[/url]
Sirius
User
Beiträge: 5
Registriert: Montag 19. Oktober 2009, 14:07

achsooo

is zwar eine komische Logik. Aber ich zähl dann halt immer 0.00001 dazu vor dem runden...

Danke
Antworten