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.

I have the following array in both MatrixForm and List form

0.474042    0.507508    0.4977      0.539773

0.473447    0.50765     0.483809    0.52489

0.46797     0.483669    0.494823    0.516956

0.467079    0.483509    0.478704    0.501286


A = {{ 0.474042, 0.507508, 0.4977,   0.539773},
     { 0.473447, 0.50765,  0.483809, 0.52489 },
     { 0.46797,  0.483669, 0.494823, 0.516956},
     { 0.467079, 0.483509, 0.478704, 0.501286}
    }

I want to get the max value of each column. I've tried the following for the first columns but no help:

Max[A[[All, 1]]]

Any comment will be greatly appreciated.

share|improve this question
3  
Max/@Transpose@A ? –  belisarius Sep 19 '13 at 19:31
1  
Well actually using Max[] on each column does the trick. Your syntax is correct for the first column. –  Wizard Sep 19 '13 at 19:32
    
I am getting weird result though. Here it's: Max[0.467079,0.46797,0.473447,0.474042] Any recommendation? –  UTK Sep 19 '13 at 19:44
    
@UTK that seems very strange as that should evaluate to 0.474042 automatically. Does Definition[Max] have anything more than just Attributes[Max]=...? If it does you can restart the kernel to reset all definitions you have made. (In the menu Evaluation->Quit kernel->Local) –  ssch Sep 19 '13 at 19:49
2  
Is it possible you have "strings" in A? Does A[[1,1]]//FullForm have " around the value? –  ssch Sep 19 '13 at 19:51

2 Answers 2

As already recommended by belisarius but once again as complete code to leave no stone unturned:

A = {{0.474042, 0.507508, 0.4977, 0.539773}, {0.473447, 0.50765, 0.483809, 
    0.52489}, {0.46797, 0.483669, 0.494823, 0.516956}, {0.467079, 0.483509, 0.478704, 
    0.501286}};

A // MatrixForm

$\left( \begin{array}{cccc} 0.474042 & 0.507508 & 0.4977 & 0.539773 \\ 0.473447 & 0.50765 & 0.483809 & 0.52489 \\ 0.46797 & 0.483669 & 0.494823 & 0.516956 \\ 0.467079 & 0.483509 & 0.478704 & 0.501286 \end{array} \right)$

Max /@ Transpose[A]
{0.474042, 0.50765, 0.4977, 0.539773}

Also less efficiently:

MapThread[Max, A]
{0.474042, 0.50765, 0.4977, 0.539773}
share|improve this answer
    
Thank you all for the comments.I have tried all of the methods that you mentioned here but for some reasons it is not working yet. I have a huge code and this matrix is in a for loop. Do you think reason might be the for loop ? I can share the part of my code if you think it helps. But it's so weird that it's not working in this code but works in other examples. –  UTK Sep 20 '13 at 14:06
    
It is working now. Thank you all. –  UTK Sep 20 '13 at 17:17
    
@UTK I'm glad you have a solution but I'm curious: what was the problem? Did you have a table of Strings as ssch suggested? –  Mr.Wizard Sep 21 '13 at 0:31
A = { {0.474042,0.507508,0.4977,0.539773},  {0.473447,0.50765,0.483809,0.52489},
     {0.46797,0.483669,0.494823,0.516956}, {0.467079,0.483509,0.478704,0.501286}}

Try

Max @ A[[All, #]] & /@ Range[4]

Which gives:

{0.474042, 0.50765, 0.4977, 0.539773}

You can also do:

Max @@@ (A\[Transpose])
share|improve this answer
    
Well, for some reasons I am getting the following: {Max[0.467079,0.46797,0.473447,0.474042], Max[0.483509,0.483669,0.507508,0.50765], Max[0.478704,0.483809,0.494823,0.4977], Max[0.501286,0.516956,0.52489,0.539773]} Any idea? –  UTK Sep 19 '13 at 19:41
    
Did you include the ampersand? I can't reproduce your result. Maybe start a new Mathematica session. –  RunnyKine Sep 19 '13 at 19:48
    
Obviously Max does not evaluate. Restart the kernel as mentioned above. –  Wizard Sep 19 '13 at 22:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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