auf numpy kahan
Suche drehte einen geschlossenen Bug/Ausgabe up
https://github.com/numpy/numpy/issues/2448 Numerische stabile Summe (ähnlich math.fsum)
ich es nicht im Detail gelesen haben. Beachten Sie den Verweis auf math.fsum
fsum(iterable)
Return an accurate floating point sum of values in the iterable.
Assumes IEEE-754 floating point arithmetic.
(from the Python math docs)
Return an accurate floating point sum of values in the iterable. Avoids loss of precision by tracking multiple intermediate partial sums
Und eine Frage SO, mit einigen Diskussionen, aber keine wirkliche Antwort:
Is there any documentation of numpy numerical stability?
Ein einfacher Vergleich:
In [320]: x=np.ones(100000)/100000
In [321]: sum(x)-1
Out[321]: -1.9162449405030202e-12
In [322]: np.sum(x)-1
Out[322]: 1.3322676295501878e-15
In [323]: math.fsum(x)-1
Out[323]: 0.0
jeweiligen Zeiten 72 ms, 304 μs, 23,8 ms
np.sum
ist eindeutig am schnellsten; aber fsum
ist besser als sum
, wahrscheinlich wegen seiner speziellen C-Implementierung.