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


closed as off-topic by Kuba, user9660, m_goldberg, MarcoB, dr.blochwave Nov 2 '15 at 13:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, Community, m_goldberg, MarcoB, dr.blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 10
    $\begingroup$ Delete[myList, List /@ positionsToRemove] should work. $\endgroup$ – C. E. Oct 26 '15 at 16:19
  • 2
    $\begingroup$ Or, if you want to use Part:: myList[[Complement[Range@Length@myList, positionsToRemove]]] $\endgroup$ – eldo Oct 26 '15 at 16:28
  • $\begingroup$ @Pickett you are correct, my bad. I will withdraw my comment. $\endgroup$ – e.doroskevic Oct 26 '15 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 '15 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 '15 at 13:19

Browse other questions tagged or ask your own question.