New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a keyword argument to diff
which preserves length
#42509
Comments
I agree with is really needed. Another possibility for the API would be to have an argument called e.g. |
The sad part about this is it's not obvious whether |
That's a reasonable point about ambiguity. But I'm not sure I've seen a context other than |
Well, given that arrays in Julia start by default with 1, I'd say the obvious formula is Thinking of it as a function in 1d is why I suggested that the natural axes for |
I don't think we should introduce Missings into arrays like this. Missings have quite unintuitive behavior for people that are not frequent users of the data science stack.
Something like this would be better imho. |
We could have |
What about NumPy syntax ( numpy.diff(a, n=1, axis=-1, prepend=<no value>, append=<no value>) |
what would be the benefit of something like |
That, and it would avoid making two allocations. |
I also think this would be useful as a so-called "window function" that preserves input length. The interface I had in mind was along the lines of diff(v, n; default) where There is a friction point in that it is not super clear to me whether the |
Just to emphasize, about The main goal of this issue (as indicated by the title) is an operation which preserves shape, not necessarily introducing I think @petvana 's idea about |
All, I have updated the initial post in this issue with a proposal of |
What about this instead: introduce a Which does bring me to this option: |
The original motivation for this issue was to prepend FWIW prepending Also note that |
We should also avoid |
Currently
Base.diff(x)
produces a new vector with lengthlength(x) - 1
.This is often annoying when working with tabular data, since you cannot do
@nalimilan recommended a keyword argument to
Base.diff
, which allows for pre-pending a default value such that length, and shape more generally in the case of matrices and other arrays, is preserved.Given the discussion in the issue below, I propose keyword arguments
fillfirst
andfilllast
which indicate the value appended to the array.The text was updated successfully, but these errors were encountered: