Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

For example, say I have a set of data which takes the form

list = {{1,2,4,5,3,2},{2,3,4,2,1,6},{2,3,4,5,4,3}}  

where all of the elements have a length of 6. Then I have to run this list through many functions each with various restrictions e.g.:


where px is the first element in the 6 vector {px,py,_,_,_,_} and py is the second element.

How would I cut the elements from the original list that do not satisfy this condition?

share|improve this question

marked as duplicate by Mr.Wizard Jun 27 '14 at 19:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I don't really get it but Select[list, #[[1]] + #[[2]] < 4 &]? – Öskå Jun 27 '14 at 15:45
Thank you. Just what I was looking for. – user16104 Jun 27 '14 at 16:04
This is an extremely common class of question. In addition to the Linked questions under the original see also e.g. (11219), (11780), (30155), (33880). For clarity I would use: Cases[list, {a_, b_, ___} /; a + b < 4]. For speed choose numeric methods using e.g. UnitStep. – Mr.Wizard Jun 27 '14 at 19:46
up vote 1 down vote accepted

For this special case you need to use Select and Part a.k.a. [[]]:

list = {{1,2,4,5,3,2},{2,3,4,2,1,6},{2,3,4,5,4,3}}  
Select[list, #[[1]] + #[[2]] < 4 &]
{{1, 2, 4, 5, 3, 2}}
share|improve this answer

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