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$

1 Answer 1

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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.