# Finding max value of each column of 4x4 Array

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.

• Max/@Transpose@A ? Sep 19, 2013 at 19:31
• Well actually using Max[] on each column does the trick. Your syntax is correct for the first column. Sep 19, 2013 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, 2013 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, 2013 at 19:49
• Is it possible you have "strings" in A? Does A[[1,1]]//FullForm have " around the value?
– ssch
Sep 19, 2013 at 19:51

## 2 Answers

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}

• 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, 2013 at 14:06
• It is working now. Thank you all.
– UTK
Sep 20, 2013 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? Sep 21, 2013 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])

• 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, 2013 at 19:41
• Did you include the ampersand? I can't reproduce your result. Maybe start a new Mathematica session. Sep 19, 2013 at 19:48
• Obviously Max does not evaluate. Restart the kernel as mentioned above. Sep 19, 2013 at 22:16