Imagine I have the following matrix: X={{0,0,0},{1,0,1},{1,1,1},{1,2,1},{3,3,3}}. I want to select the sublists that are greater or equal than this list T={0,1,1}. Greater in the sense that X[[]]-T has no negative entries. The output should look like R={{1,1,1},{1,2,1},{3,3,3}}, since all elements of the sublists are equal of greater than the elements of the list T compared element by element. Thanks for help!

Thanks for the quick answers. I have searched myself meanwhile and found this one:

Higher[C_] := Select[B, NonNegative[Min[#[[]] - C[[]]]] &];

Does it seem right?


2 Answers 2

X = Table[RandomInteger[{-10, 10}], {30}, {3}]



Select[X, And @@ Thread[# > {0, 1, 1}] &]

or slower one:

Select[X, (! MemberQ[# - {0, 1, 1}, _?NonPositive]) &]
  • $\begingroup$ Thanks Kuba! It works perfectly! Which one do you recommend I use for efficiency purposes! The one you suggested or the one I found above? Thanks. :) $\endgroup$ Jun 25, 2013 at 5:30

If x is short then it probably doesn't matter much how you do it,
but if x is long then Pick is clearly faster than either Select.
The trick is to operate on a few long vectors (the columns of x)
rather than many short vectors (the rows of x).

t = {0,1,1}; Dimensions[x = RandomInteger[3, {10^5, 3}]]
(* {100000, 3} *)

(* {1.888830, {56520, 3}} *)

(* {2.005653, {56520, 3}} *)

(* {0.275097, {56520, 3}} *)

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.