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
Missing diff #1634
Comments
You can use
The function |
More over your code gives |
The answer would be, but nevertheless maybe somebody just want to add it to mathjs? x = [..., .. ,..]
y = [..., ..,..]
// Assuming both x & y are the same length
var diff = x.map((value, index) => value - y[index]) |
Hi, |
That's odd, it works for me on the MathJS site. Maybe someone else can chime in on this. |
Thanks for your suggestion Melroy, would be nice to add a function @LloydLS the function Before implementing Anyone interested in implementing |
I wrote a function called e.g. largeAdd = (a, b, c, d, e, f, g, h) => a + b + c + d + e + f + g + h //<- 8 elements
arr = [1, 2, 3, 4, 5, 6, 7, 8] or matrix([1, 2, 3, 4, 5, 6, 7, 8]) //<- 8 elements
math.crush(arr, largeAdd) returns [36] or matrix([36]) //<- 1 element I wrote it this way becuase it allows it to be slightly more general kinda like the map function than just implementing a diff function, which didnt take very long when I tried it originally. @josdejong What are your thoughts? Is this the sort of thing you were thinking of? EDIT: In the c++ standard library they have a diff function similar to the numpy one called adjacent_diff. Maybe a better name for this function if it were implemented would be |
That is an interesting approach. So this way you can pass any function which will be applied to every pair of two elements, but also can loop over every set of 3 or 8 elements as in your example. I guess you can use that for calculating sliding windows and things like that? Can you give some usecases for this function I think the function I'm not sure about the naming, I see Matlab and Python both use |
Yeah that does make sense. I was just trying to generalise but I guess its not common enough to need that as the diff function would be the only example that would need it. |
👍 let's start simple then and see how it evolves :) |
Closing this issue, |
Hi,
I have an array of numbers, I would like to calculate the diffs between them.
Just like the numpy diff.
Is that possible?
Ps. this is definitely not the same as your
math.setDifference
!Regards,
Melroy
The text was updated successfully, but these errors were encountered: