[Numpy-discussion] Re: Add to NumPy a function to compute cumulative sums from 0.

2024-03-20 Thread john . dawson
Yet another example is ``` d = np.zeros(n) d[1:] = np.linalg.norm(np.diff(points, axis=1), axis=0) r = d.cumsum() ``` https://github.com/WarrenWeckesser/ufunclab/blob/main/examples/linear_interp1d_demo.py#L13-L15 ___ NumPy-Discussion mailing list -- numpy

[Numpy-discussion] Re: Add to NumPy a function to compute cumulative sums from 0.

2023-08-22 Thread john . dawson
Dom Grigonis wrote: > 1. Dimension length stays constant, while cumusm0 extends length to n+1, then > np.diff, truncates it back. This adds extra complexity, while things are very > convenient to work with when dimension length stays constant throughout the > code. For n values there are n-1 di

[Numpy-discussion] Re: Add to NumPy a function to compute cumulative sums from 0.

2023-08-15 Thread john . dawson
> From my point of view, such function is a bit of a corner-case to be added to > numpy. And it doesn’t justify it’s naming anymore. It is not one operation > anymore. It is a cumsum and prepending 0. And it is very difficult to argue > why prepending 0 to cumsum is a part of cumsum. That is ba

[Numpy-discussion] Add to NumPy a function to compute cumulative sums from 0.

2023-08-11 Thread john . dawson
`cumsum` computes the sum of the first k summands for every k from 1. Judging by my experience, it is more often useful to compute the sum of the first k summands for every k from 0, as `cumsum`'s behaviour leads to fencepost-like problems. https://en.wikipedia.org/wiki/Off-by-one_error#Fencepos