Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted
X = Table[RandomInteger[{-10, 10}], {30}, {3}]

1

Faster

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

or slower one:

Select[X, (! MemberQ[# - {0, 1, 1}, _?NonPositive]) &]
share|improve this answer
    
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. :) –  Friedrich Nietzsche Jun 25 '13 at 5:30
add comment

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} *)

AbsoluteTiming@Dimensions@Select[x,NonNegative@Min[#-t]&]
(* {1.888830, {56520, 3}} *)

AbsoluteTiming@Dimensions@Select[x,And@@Thread[#>=t]&]
(* {2.005653, {56520, 3}} *)

AbsoluteTiming@Dimensions@Pick[x,Total@UnitStep[Transpose@x-t],3]
(* {0.275097, {56520, 3}} *)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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