Filtering two arrays to avoid Inf/NaN values
Posted
by Gacek
on Stack Overflow
See other posts from Stack Overflow
or by Gacek
Published on 2010-05-07T16:26:41Z
Indexed on
2010/05/07
16:38 UTC
Read the original article
Hit count: 202
I have two arrays of doubles of the same size, containg X and Y values for some plots.
I need to create some kind of protection against Inf/NaN values. I need to find all that pairs of values (X, Y) for which both, X and Y are not Inf nor NaN
If I have one array, I can do it using lambdas:
var filteredValues = someValues.Where(d=> !(double.IsNaN(d) || double.IsInfinity(d))).ToList();
Now, for two arrays I use following loop:
List<double> filteredX=new List<double>();
List<double> filteredX=new List<double>();
for(int i=0;i<XValues.Count;i++)
{
if(!double.IsNan(XValues[i]) &&
!double.IsInfinity(XValues[i]) &&
!double.IsNan(YValues[i]) &&
!double.IsInfinity(YValues[i]) )
{
filteredX.Add(XValues[i]);
filteredY.Add(YValues[i]);
}
}
Is there any way of filtering two arrays at the same time using LINQ/Lambdas, as it was done for single array?
© Stack Overflow or respective owner