Skip to main content
deleted 4 characters in body
Source Link
Fred Simons
  • 10.2k
  • 19
  • 50

The solution by @DumpsterDoofus is no doubt the simplest and most elegant Mathematica solution. Just for fun I wrote a more direct construction, that gives both the maxima and their positions.

mat={{0.803279,0.958913,0.600443,0.928255,0.425632,0.165858},
  {0.550107,0.929972,0.990928,0.110509,0.803279,0.939139},
  {0.693203,0.823982,0.645499,0.617851,0.461366,0.252978},
  {0.277155,0.321569,0.796915,0.976772,0.462962,0.944314}};

maxvalues=mat[[1]];
maxpositions=Table[1, {Length[mat[[1]]]}];
Do[
  maxpositions=MapThread[Max, {maxpositions,  n  UnitStep[mat[[n]]Sign[mat[[n]] - maxvalues]}];
   maxvalues=MapThread[Max,{maxvalues, mat[[n]]}],
  {n, 2, Length[mat]}];
maxvalues
maxpositions

(* {0.803279,0.958913,0.990928,0.976772,0.803279,0.944314} *)

(* {1,1,2,4,2,4} *)

The solution by @DumpsterDoofus is no doubt the simplest and most elegant Mathematica solution. Just for fun I wrote a more direct construction, that gives both the maxima and their positions.

mat={{0.803279,0.958913,0.600443,0.928255,0.425632,0.165858},
  {0.550107,0.929972,0.990928,0.110509,0.803279,0.939139},
  {0.693203,0.823982,0.645499,0.617851,0.461366,0.252978},
  {0.277155,0.321569,0.796915,0.976772,0.462962,0.944314}};

maxvalues=mat[[1]];
maxpositions=Table[1, {Length[mat[[1]]]}];
Do[
  maxpositions=MapThread[Max, {maxpositions,  n  UnitStep[mat[[n]] - maxvalues]}];
   maxvalues=MapThread[Max,{maxvalues, mat[[n]]}],
  {n, 2, Length[mat]}];
maxvalues
maxpositions

(* {0.803279,0.958913,0.990928,0.976772,0.803279,0.944314} *)

(* {1,1,2,4,2,4} *)

The solution by @DumpsterDoofus is no doubt the simplest and most elegant Mathematica solution. Just for fun I wrote a more direct construction, that gives both the maxima and their positions.

mat={{0.803279,0.958913,0.600443,0.928255,0.425632,0.165858},
  {0.550107,0.929972,0.990928,0.110509,0.803279,0.939139},
  {0.693203,0.823982,0.645499,0.617851,0.461366,0.252978},
  {0.277155,0.321569,0.796915,0.976772,0.462962,0.944314}};

maxvalues=mat[[1]];
maxpositions=Table[1, {Length[mat[[1]]]}];
Do[
  maxpositions=MapThread[Max, {maxpositions,  n  Sign[mat[[n]] - maxvalues]}];
   maxvalues=MapThread[Max,{maxvalues, mat[[n]]}],
  {n, 2, Length[mat]}];
maxvalues
maxpositions

(* {0.803279,0.958913,0.990928,0.976772,0.803279,0.944314} *)

(* {1,1,2,4,2,4} *)

added 2 characters in body
Source Link
Fred Simons
  • 10.2k
  • 19
  • 50

The solution by @DumpsterDoofus is no doubt the simplest and most elegant Mathematica solution. Just for fun I wrote a more direct construction, that gives both the maxima and their positions.

mat={{0.803279,0.958913,0.600443,0.928255,0.425632,0.165858},
  {0.550107,0.929972,0.990928,0.110509,0.803279,0.939139},
  {0.693203,0.823982,0.645499,0.617851,0.461366,0.252978},
  {0.277155,0.321569,0.796915,0.976772,0.462962,0.944314}};

maxvalues=mat[[1]];
maxpositions=Table[1, {Length[mat[[1]]]}];
Do[
  maxpositions=MapThread[Max, {maxpositions,  n (Sign[mat[[n]] UnitStep[mat[[n]] -maxvalues]+1)/2 maxvalues]}];
   maxvalues=MapThread[Max,{maxvalues, mat[[n]]}],
  {n, 2, Length[mat]}];
maxvalues
maxpositions

(* {0.803279,0.958913,0.990928,0.976772,0.803279,0.944314} *)

(* {1,1,2,4,2,4} *)

The solution by @DumpsterDoofus is no doubt the simplest and most elegant Mathematica solution. Just for fun I wrote a more direct construction, that gives both the maxima and their positions.

mat={{0.803279,0.958913,0.600443,0.928255,0.425632,0.165858},
  {0.550107,0.929972,0.990928,0.110509,0.803279,0.939139},
  {0.693203,0.823982,0.645499,0.617851,0.461366,0.252978},
  {0.277155,0.321569,0.796915,0.976772,0.462962,0.944314}};

maxvalues=mat[[1]];
maxpositions=Table[1, {Length[mat[[1]]]}];
Do[
  maxpositions=MapThread[Max, {maxpositions, n (Sign[mat[[n]]-maxvalues]+1)/2}];
   maxvalues=MapThread[Max,{maxvalues, mat[[n]]}],
  {n, 2, Length[mat]}];
maxvalues
maxpositions

(* {0.803279,0.958913,0.990928,0.976772,0.803279,0.944314} *)

(* {1,1,2,4,2,4} *)

The solution by @DumpsterDoofus is no doubt the simplest and most elegant Mathematica solution. Just for fun I wrote a more direct construction, that gives both the maxima and their positions.

mat={{0.803279,0.958913,0.600443,0.928255,0.425632,0.165858},
  {0.550107,0.929972,0.990928,0.110509,0.803279,0.939139},
  {0.693203,0.823982,0.645499,0.617851,0.461366,0.252978},
  {0.277155,0.321569,0.796915,0.976772,0.462962,0.944314}};

maxvalues=mat[[1]];
maxpositions=Table[1, {Length[mat[[1]]]}];
Do[
  maxpositions=MapThread[Max, {maxpositions,  n  UnitStep[mat[[n]] - maxvalues]}];
   maxvalues=MapThread[Max,{maxvalues, mat[[n]]}],
  {n, 2, Length[mat]}];
maxvalues
maxpositions

(* {0.803279,0.958913,0.990928,0.976772,0.803279,0.944314} *)

(* {1,1,2,4,2,4} *)

Source Link
Fred Simons
  • 10.2k
  • 19
  • 50

The solution by @DumpsterDoofus is no doubt the simplest and most elegant Mathematica solution. Just for fun I wrote a more direct construction, that gives both the maxima and their positions.

mat={{0.803279,0.958913,0.600443,0.928255,0.425632,0.165858},
  {0.550107,0.929972,0.990928,0.110509,0.803279,0.939139},
  {0.693203,0.823982,0.645499,0.617851,0.461366,0.252978},
  {0.277155,0.321569,0.796915,0.976772,0.462962,0.944314}};

maxvalues=mat[[1]];
maxpositions=Table[1, {Length[mat[[1]]]}];
Do[
  maxpositions=MapThread[Max, {maxpositions, n (Sign[mat[[n]]-maxvalues]+1)/2}];
   maxvalues=MapThread[Max,{maxvalues, mat[[n]]}],
  {n, 2, Length[mat]}];
maxvalues
maxpositions

(* {0.803279,0.958913,0.990928,0.976772,0.803279,0.944314} *)

(* {1,1,2,4,2,4} *)