0
$\begingroup$

l and b are two lists of vectors with different length. I need the list of vectors that is constructed by adding each member of b to each member of l (resulting in a list with length $|l|\times |b|$). This can be done by

t = Join@Flatten[Table[Map[# + b[[i]] &, l], {i, Length[b]}], 1]

Can this be done by mapping something like #1+#2& to the lists? Thanks!

$\endgroup$
2
$\begingroup$

Outer and Tuples may be helpful, e.g.

l1 = {1, 2, 3}
l2 = {4, 5, 6, 7}
Total /@ Tuples[{l1, l2}]
Join @@ Outer[Plus, l1, l2]

yields:{5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10}

or symbolically,

Join @@ Outer[Plus, {a, b, c}, {d, e, f, g, h}]

gives: {a + d, a + e, a + f, a + g, a + h, b + d, b + e, b + f, b + g, b + h, c + d, c + e, c + f, c + g, c + h}

$\endgroup$

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.