I normally use python but am learning C#, is there a preexisting class in C# for getting an element-by-element difference of an array to basically get a derivative, like numpy.diff in python?
Asked
Active
Viewed 1,274 times
2
-
1Do you have meaningful sample data, have you tried something? – Tim Schmelter Mar 06 '15 at 16:06
-
1blinkenlight already basically did it...thanks. – wordsforthewise Mar 13 '15 at 00:34
1 Answers
8
According to this page, numpy.diff
does this:
>>> x = np.array([1, 2, 4, 7, 0])
>>> np.diff(x)
array([ 1, 2, 3, -7])
If this is the effect that you want to see, use LINQ:
var np = new [] {1, 2, 4, 7, 0};
var res = np.Zip(np.Skip(1), (a,b)=>b-a).ToArray();

Sergey Kalinichenko
- 714,442
- 84
- 1,110
- 1,523