Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I have given an example to find the maximum value and its place in the list. Is it possible to find the local maximum in the sub-list of this list means local maximum in the each row of the list and its place.

{{0.798434, 0.836162, 0.866566, 0.891023, 0.910648, 0.926344, 
 0.938842, 0.948735, 0.956506, 0.962542, 0.967162, 0.970621, 
 0.973129, 0.974854, 0.975934, 0.976483, 0.97659, 0.976331, 0.975766,
 0.974944, 0.973908}, {0.805793, 0.871229, 0.913967, 0.941624, 
0.959219, 0.970068, 0.976365, 0.979565, 0.980639, 0.980232, 0.97878,
 0.976576, 0.97382, 0.970649, 0.967158, 0.963416, 0.95947, 0.955357,
0.951105, 0.946734, 0.942261}, {0.806828, 0.895766, 0.943, 
0.967386, 0.979126, 0.983757, 0.984299, 0.982413, 0.979023, 
0.974652, 0.969603, 0.964063, 0.958146, 0.951933, 0.94548, 0.93883, 
0.932018, 0.925073, 0.918018, 0.910877, 0.903666}}
share|improve this question

marked as duplicate by Pickett, rasher, Michael E2, Kuba, Yves Klett May 22 at 8:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Welcome to Mathematica.SE, so just to be clear: you want to find the maximum value in each column of the given matrix? –  Pickett May 21 at 23:15
    
yes and its place... –  santosh May 21 at 23:16
    
I'm still uncertain about what you are asking. You give a 3 x 21 matrix. You mention the maximum for the whole matrix, the maximum in each "sub-list" (3 values) and the maximum for each column (21 values). Which do you want? –  m_goldberg May 21 at 23:30
    
maximum in each "sub-list" (3 values) –  santosh May 21 at 23:33
1  
The positions are given by pos=Last@Ordering@#&/@list, so to get the value and the position you can do something like {#,list[[#]]}&/@pos. –  Pickett May 21 at 23:44

1 Answer 1

up vote 1 down vote accepted

This problem can be tackled in many ways with Mathematica. Here is one way to do it.

data =
  {{0.798434, 0.836162, 0.866566, 0.891023, 0.910648, 0.926344, 
    0.938842, 0.948735, 0.956506, 0.962542, 0.967162, 0.970621, 
    0.973129, 0.974854, 0.975934, 0.976483, 0.97659, 0.976331, 0.975766,
    0.974944, 0.973908}, 
   {0.805793, 0.871229, 0.913967, 0.941624, 
    0.959219, 0.970068, 0.976365, 0.979565, 0.980639, 0.980232, 0.97878,
    0.976576, 0.97382, 0.970649, 0.967158, 0.963416, 0.95947, 0.955357,
    0.951105, 0.946734, 0.942261}, 
   {0.806828, 0.895766, 0.943, 
    0.967386, 0.979126, 0.983757, 0.984299, 0.982413, 0.979023, 
    0.974652, 0.969603, 0.964063, 0.958146, 0.951933, 0.94548, 0.93883, 
    0.932018, 0.925073, 0.918018, 0.910877, 0.903666}};

rowMaxes[data_] :=
  Module[{vals, indxs},
    vals = Max /@ data;
    indxs = Thread[{
              Range @ Length @ data,
              Flatten[First /@ MapThread[Position, {data, vals}]]
            }];
    Thread[{vals, indxs}]]
rowMaxes[data]
{{0.97659, {1, 17}}, {0.980639, {2, 9}}, {0.984299, {3, 7}}}

This solution is more messy than I would like, but I had to be careful not to get tripped up by repeated values, such as in this example:

intData = {{1, 2, 4, 4}, {4, 5, 7, 4}, {1, 2, 10, 4}};
rowMaxes[intData]
{{4, {1, 3}}, {7, {2, 3}}, {10, {3, 3}}}
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.