I'm essentially doing coin flips, using RandomReal
to populate a bunch of lists, each with 8 elements. I then want to select only those lists for which all elements are greater than a certain number, e.g. .5.
So far I have this:
class = RandomReal[1, {100, 8}];
pass = Select[class, #[[1]] > (.5) &]
but this doesn't work. I suspect a simple Select function would do the trick, but I can't seem to get the syntax right to test every element of the nested listed against a certain number and then only return those lists for which every element passes. Or indeed simply to return the number of sublists for which every element passes. Thanks.
Select[class, And @@ Thread[# > .5] &]
$\endgroup$Select[class, And @@ Map[# > 0.5 &, #] &]
. Performance-wise, you'd be better off with something likeSelect[class, Total[UnitStep[0.5 - #]] == 0 &]
. $\endgroup$Pick[class,Times @@ UnitStep[#] == 1 & /@ (class - 0.5)]
$\endgroup$Pick[#, Sign[(Min /@ #) - #2], 1] &[class, .5]
probably about as fast as possible, change second argument obviously for limit. Properly returns those sublists where all members are greater as your OP states. $\endgroup$