diff options
author | Atharva-Vidwans <57441520+Atharva-Vidwans@users.noreply.github.com> | 2021-05-17 08:03:23 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-16 19:33:23 -0700 |
commit | 99bb6a48ced27e5ce7bbf1fc7b606c5bd840af3a (patch) | |
tree | 774fb3083cc768cc918b880fe1e2e51e766b7e19 /numpy/core/fromnumeric.py | |
parent | b47a92ae5c95d327447e2b14ddda269bf9a1fdbb (diff) | |
download | numpy-99bb6a48ced27e5ce7bbf1fc7b606c5bd840af3a.tar.gz |
DOC: Improve cumsum documentation (#18895)
Add note and example potential differences with np.sum.
Co-authored-by: Matti Picus <matti.picus@gmail.com>
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r-- | numpy/core/fromnumeric.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 5c7b3372b..65a42eb1e 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -2498,6 +2498,10 @@ def cumsum(a, axis=None, dtype=None, out=None): Arithmetic is modular when using integer types, and no error is raised on overflow. + ``cumsum(a)[-1]`` may not be equal to ``sum(a)`` for floating-point + values since ``sum`` may use a pairwise summation routine, reducing + the roundoff-error. See `sum` for more information. + Examples -------- >>> a = np.array([[1,2,3], [4,5,6]]) @@ -2516,6 +2520,14 @@ def cumsum(a, axis=None, dtype=None, out=None): array([[ 1, 3, 6], [ 4, 9, 15]]) + ``cumsum(b)[-1]`` may not be equal to ``sum(b)`` + + >>> b = np.array([1, 2e-9, 3e-9] * 1000000) + >>> b.cumsum()[-1] + 1000000.0050045159 + >>> b.sum() + 1000000.0050000029 + """ return _wrapfunc(a, 'cumsum', axis=axis, dtype=dtype, out=out) |