3
$\begingroup$

I would like to pick up n (2 in example) columns from matrix. The sum/total of these columns should be minimal.

m = Table[Random[], {i, 1, 10}, {j, 1, 10}];
f[q_] := Module[{}, q1 = Round[q]; Total[Total[m[[All, q1]]]]];
FindMinimum[f[{x, y}], {{x, 1}, {y, 2}}]

Thank You for any help

$\endgroup$
0

1 Answer 1

2
$\begingroup$
SeedRandom@1
m = RandomInteger[4, {3, 4}];
n = 2;

m // MatrixForm

enter image description here

The n largest smallest column totals

Transpose @ MinimalBy[Transpose @ m, Total, n] // MatrixForm

enter image description here

The n smallest row totals

MinimalBy[m, Total, n] // MatrixForm

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, any chance to do it with FindMinimum/NMinimize? $\endgroup$
    – Eduard
    Jul 6, 2017 at 11:46
  • $\begingroup$ FindMinimum / NMinimize wouldn' t function here $\endgroup$
    – eldo
    Jul 6, 2017 at 11:55

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.