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$
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$
  • $\begingroup$ Thanks, any chance to do it with FindMinimum/NMinimize? $\endgroup$ – Eduard Jul 6 '17 at 11:46
  • $\begingroup$ FindMinimum / NMinimize wouldn' t function here $\endgroup$ – eldo Jul 6 '17 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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