I'm attempting to remove all points in an array which are within a Euclidean distance "ThresDist" of one-another. Using the command:

DeleteDuplicates[List, EuclideanDistance[#1, #2] <= ThresDist &];

I can remove one point in a pair of points that fall within a distance "ThresDist" of one-another. However:

DeleteCases[List, EuclideanDistance[#1, #2] <= ThresDist  &];

Fails to work similarly. Is there something wrong with my approach?

Note : I made a typo earlier in writing DeleteCases, and also used a poor variable name. This was sloppy of me.

As for the actual question - how might I best accomplish my goal? I've searched through Mathematica's function directory, and I can't seem to find an appropriate way to prune not just a duplicate point, but all points that fall within a threshold distance of one-another?

  • $\begingroup$ DeleteDCases is spelt incorrectly but assuming this is a typo. For DeleteCases you need to use a pattern and you will be parsing one argument to a function used as a pattern test or to a pattern condition $\endgroup$ Jul 18, 2013 at 1:40
  • $\begingroup$ I just updated my answer with relevant links; please read those and let us know if you have additional questions. $\endgroup$
    – Mr.Wizard
    Jul 18, 2013 at 2:22

1 Answer 1


You seem to be new around here so I am going to answer this, but others may close it as "a simple mistake."

  • D is a reserved (System) Symbol; use d or dist etc. instead.

  • DeleteDCases should be DeleteCases.

  • DeleteCases looks at each element independently, not pairs of elements as does DeleteDuplicates (when using a custom equivalence function).

  • DeleteCases requires a pattern, not a function, for the second argument.

Since you are making a number of mistakes I shall direct you to this massive omnibus collection of instructional resources:

Where can I find examples of good Mathematica programming practice?

In response to your updated question, specifically:

As for the actual question - how might I best accomplish my goal?

Please see:

Also related:

  • $\begingroup$ I changed the actual variable name when I wrote this question to simplify things, and I have now fixed the problem. There was a typo for DeleteCases, and that has been fixed. $\endgroup$ Jul 18, 2013 at 1:47
  • $\begingroup$ @Intemediocre Okay. I believe the other points still apply; I hope you find them helpful. $\endgroup$
    – Mr.Wizard
    Jul 18, 2013 at 1:50
  • 1
    $\begingroup$ Yes, it's very helpful to know that DeleteCases and DeleteDuplicates don't work in the same manner! $\endgroup$ Jul 18, 2013 at 1:52
  • 1
    $\begingroup$ Personally, I find these types of questions and answers beneficial to newcomers, so long as there are sufficient keywords to provide positive search results for future newcomers. $\endgroup$ Jul 18, 2013 at 2:37
  • $\begingroup$ @bobthechemist I have no problem with these myself, so long as they are not frequent or persisting, but I am trying to respect community opinion as well. I only meant to warn the user that such questions might be closed by those who feel that they are too basic. $\endgroup$
    – Mr.Wizard
    Jul 18, 2013 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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