1
$\begingroup$

i have two tuples select done with modulo on a range {-1,1} :

Select[Tuples[Range[-1, 1], 3], Mod[Total[#], 1] == 0 &]

and

Select[Tuples[Range[-1, 1], 3], Mod[Total[#], 2] == 0 &]

these generates coordinates for centers of spheres .

I am trying to filter the first select (mod 1) to remove the result of the second select (mod 2) from it in order to remove the coordinates that match in the two select from the final result.

How can it be achieved ?

$\endgroup$
  • $\begingroup$ Related $\endgroup$ – Stitch Jan 23 '17 at 22:24
1
$\begingroup$
ClearAll[f, g]
f = Select[Tuples[Range[-1, 1], 3], Mod[Total[#], 1] == 0 &]
g = Select[Tuples[Range[-1, 1], 3], Mod[Total[#], 2] == 0 &]

If we want to delete g from f:

DeleteCases[f, Alternatives @@ g]

Fold[Cases[#1, Except@#2] &,f,g]
$\endgroup$
  • 1
    $\begingroup$ Complement[f, g] is way more compact. $\endgroup$ – J. M. will be back soon Jan 24 '17 at 2:41
  • $\begingroup$ @J.M. Absolutely! $\endgroup$ – Stitch Jan 24 '17 at 2:42

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.