Using LINQ to Obtain Max of Columns for Two Dimensional Arrays
Posted
by Ngu Soon Hui
on Stack Overflow
See other posts from Stack Overflow
or by Ngu Soon Hui
Published on 2010-04-06T04:24:54Z
Indexed on
2010/04/06
4:33 UTC
Read the original article
Hit count: 273
Is there anyway to use LINQ to obtain the maximum of each columns for two dimensional arrays?
Assume that I have the following:
var arrays = new double[5,100]();
I want to get the maximum of arrays[0,:]
, arrays[1,:]
.... arrays[4,:]
. How to use LINQ to do it?
I could have use such method
public double GetMax(double[,] arr, int rowIndex)
{
var colCount = arr.GetLength(1);
double max = 0.0;
for(int i=0; i<colCount; i++)
{
max=Math.Max(Math.Abs(arr[rowIndex, i]), max);
}
return max;
}
But I would prefer a more succinct ways of doing things.
© Stack Overflow or respective owner