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

Just on my free trial and can't find this anywhere in online docs. Trying to use the Mod function as follows: Mod[{list},{list}} where it takes each number in list one mod each number in list two, but I get the error "Objects of unequal length in Mod cannot be combined." For instance, Mod[{55,76},{10,3,7}] yielding {5,1,6} for 55 and {6,1,6} for 76. Any way to do this?

share|improve this question
"Objects of unequal length in Mod cannot be combined." means what it says. Unless your two lists have the same dimensions, it doesn't work. Shorten one, or lengthen the other. – J. M. Feb 22 at 4:53
Do you want the output would be in the form {Mod[list1[[1]], list2[[1]]], Mod[list1[[2]], list2[[2]]], ...} or {{Mod[list1[[1]], list2[[1]]], Mod[list1[[1]], list2[[2]]], ...}, {Mod[list1[[2]], list2[[1]]], Mod[list1[[2]], list2[[2]]], ...}, ... }? Please specify! If the latter is the case, C. Woods' answer would be appropriate. – JHM Feb 22 at 5:07
@JHM, I was under the impression that Mod was listable. In any case, it seems like his error was about "objects of unequal length" so seems like he was trying to do something like in the latter case. That's why I gave my answer about Outer. :) – C. Woods Feb 22 at 5:13
@JHM Sorry my question was unclear. I've edited it now. I think this fits your first example better, but I'm unsure. – Elem-Teach-w-Bach-n-Math-Ed Feb 22 at 6:58
@user3363795 the answer by @C.Woods or Map[#,list2]&/@list1 – ubpdqn Feb 22 at 7:01
up vote 12 down vote accepted

Yes, you can use the built in function Outer. It does exactly the kind of thing you are talking about it. Try

Outer[Mod, list1, list2]

Outer is a generalization of the outer product in Linear Algebra. Its first argument is a function, and the rest of its arguments are lists. Basically, it applies the function in the first argument to every element in the Cartesian product of the rest of the arguments. This is useful for doing things like you are trying to do: e.g. apply this function to every possible combination of these things.

share|improve this answer
This would give all possible combination of Mods, wouldn't it? – JHM Feb 22 at 5:03
@JHM, To be fair, the OP could have given an explicit example so that we aren't guessing... – J. M. Feb 22 at 5:06
This got it working! Thanks everyone! – Elem-Teach-w-Bach-n-Math-Ed Feb 22 at 7:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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