You are looking for Zip
method
var data3 = data1.Zip(data2, (d1,d2) => Math.Abs(d1 - d2)).ToArray();
Enumerable.Zip<TFirst, TSecond, TResult> Method
Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.
So it simply takes each corresponding element, e.g data1[0]
and data2[0]
, then data1[1]
and data2[1]
so on.. then applies the function Math.Abs(d1-d2)
which simply substracts two numbers and gets the absolute value of the result. Then returns a sequence which contains the result of each operation.