Tag Info

Hot answers tagged

4

I propose using Order, assuming equal-length lists. Order[{1, 3, 5}, {1, 3, 4}] Order[{1, 3, 5}, {1, 5, 2}] Order[{1, 3, 5}, {1, 3, 5}] -1 1 0 You can assign an infix operator if you wish: CirclePlus = Order; {1, 3, 5} ⊕ {1, 3, 4} {1, 3, 5} ⊕ {1, 5, 2} {1, 3, 5} ⊕ {1, 3, 5} -1 1 0 You can convert the numeric output to Boolean as needed, ...


3

listGreater[l1_, l2_] := OrderedQ@{l2, l1}&& l1 =!= l2 listLess[l1_, l2_] := OrderedQ@{l1, l2}&& l1 =!= l2 listGreaterEqual[l1_, l2_] := OrderedQ@{l2, l1} listLessEqual[l1_, l2_] := OrderedQ@{l1, l2} {1, 3, 5}~listGreater~{1, 3, 4} (* True *)


2

Adapting listMaxArg from linked topic seems to be the fastest. list = RandomReal[1, {10^6, 2}]; list[[Ordering[list[[All, 2]], 1]]] // AbsoluteTiming {0.010000, {{0.817248, 6.71112*10^-7}}}


2

The reason why the second method is failing is because you are looking for a pair whose second element is the minimum over the whole list (including all the first elements). This of course will fail whenever the global minimum is in the first position. The proper syntax is Cases[list, {_, Min[list[[All, 2]]]}] The speed improvement, on the other hand, is ...


2

The fastest I can come up with is (by separating finding the minimum second value in each pair): AbsoluteTiming@With[{min = Min@list[[All, 2]]}, Cases[list, {_, min}]] (* {1.288129, {{0.555911, 1.05947*10^-6}}} *) while MinimalBy takes much longer: AbsoluteTiming@MinimalBy[list, #[[2]]&] (* {2.074207, {{0.555911, 1.05947*10^-6}}} *) Your second ...



Only top voted, non community-wiki answers of a minimum length are eligible