Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get minimum value in two dimensional array for given index?

double[] tab = new double[10];

I know I can gen minimum by tab.Min().

double[,] tab = new double[10,2]; 

This is table of coordinates, in 2nd index 0 is x and 1 is y. There are 10 points.

How can I get minimum (and maximum) value of x and y?

In other words:

minX is the smallest value in 1st column (second index=0 e.g tab[xxx, 0]);
minY is the smallest value in 2nd column (second index=1 e.g tab[xxx, 1]);

like image 616
Miko Kronn Avatar asked Jan 09 '11 21:01

Miko Kronn


1 Answers

var doubles = new double[4,2]{{1,2},{4,5},{7,8},{9,1}};
var min = System.Linq.Enumerable.Range(0, 4).Select(i => doubles[i, 1]).Min();

OR

var doubles = new double[4,2]{{1,2},{4,5},{7,8},{9,1}};
var min = System.Linq.Enumerable.Range(0, doubles.GetUpperBound(0)+1)
                                .Select(i => doubles[i, 1]).Min();
like image 182
Jahan Zinedine Avatar answered Nov 08 '22 00:11

Jahan Zinedine