I have a list of points in 2d:

myList = {{x1,y1},... , {xn,yn}}

And a range of points I want to remove from the list, for instance:

positionsToRemove = {3,4,5,..,87,88,...,967,...}

(I am deleting the closed loops of my path.)

It looks like the delete function can only take one index at the time. Is there a way to pick the elements outside of the range given by positionsToRemove?

Something like:

myList[[~positionsToRemove]] (*returns all the points but the positions passed*)

I see how do it in Python but I am totally new to this Mathematica thing :O

  • 10
    $\begingroup$ Delete[myList, List /@ positionsToRemove] should work. $\endgroup$
    – C. E.
    Oct 26, 2015 at 16:19
  • 2
    $\begingroup$ Or, if you want to use Part:: myList[[Complement[Range@Length@myList, positionsToRemove]]] $\endgroup$
    – eldo
    Oct 26, 2015 at 16:28
  • $\begingroup$ @Pickett you are correct, my bad. I will withdraw my comment. $\endgroup$ Oct 26, 2015 at 16:45
  • 5
    $\begingroup$ Delete will work, but how did you find these positions in the first place? Most of the time one would use some test, applied to each element of the list, to decide whether to remove them. If this is how you got the positions, there may be much faster ways to accomplish the deletion than this. Look up Select, Cases, DeleteCases, Pick, and take a look at this. $\endgroup$
    – Szabolcs
    Oct 26, 2015 at 17:01
  • $\begingroup$ The third example under Basic Examples in the Delete documentation gives the form of Delete you are looking for. $\endgroup$
    – m_goldberg
    Nov 2, 2015 at 13:19


Browse other questions tagged or ask your own question.