3
$\begingroup$

I have a table with this format. How can I get the minimum value of every group and put it in another list?

{{x1, x2, x3, x4}, {x5, x6, x7, x8}, {x9, x10, x11, x12}}
$\endgroup$
2
  • 6
    $\begingroup$ Min /@ yourList? Look up Map in the documentation (its infix form is /@). $\endgroup$
    – MarcoB
    Commented Apr 22, 2020 at 5:22
  • $\begingroup$ Thank you very much. $\endgroup$
    – user72169
    Commented Apr 22, 2020 at 5:26

3 Answers 3

2
$\begingroup$
m = 
 {{4, 2, 3, 1}, 
  {5, 8, 5, 7}, 
  {4, 3, 3, 3}};

Using ArrayReduce (new in 12.2)

Row Minima

ArrayReduce[Min, m, 2]

{1, 5, 3}

Column Minima

ArrayReduce[Min, m, 1]

{4, 2, 3, 1}

$\endgroup$
1
$\begingroup$
m = {{4, 2, 3, 1}, {5, 8, 5, 7}, {4, 3, 3, 3}};

Using Outer, Thread and Min:

{#, Min @@@ Outer[List, #] & /@ {#, Thread@#} &@#} &@m

(*{{{4, 2, 3, 1}, {5, 8, 5, 7}, {4, 3, 3, 3}}, {{1, 5, 3}, {4, 2, 3, 1}}}*)
$\endgroup$
1
$\begingroup$

Random enough but the results can be verified easily by inspection with the following strategy.

SeedRandom[11];
(m = Range[21] // Partition[#, 7] & // 
    RotateLeft[#, {4, 1}] &) // MatrixForm

RankedMin[#, 1] & /@ m

MinimalBy[#, # &] & /@ m // Flatten

Min /@ m (* comment from @MarcoB *)

Result::

{8, 15, 1}

For columns, use Transpose@m with all variants, e.g. :

Min /@ Transpose@m

{4, 5, 6, 7, 1, 2, 3}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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