# Multiplying lists

**URL:** <https://community.wolfram.com/t/multiplying-lists/6121>\
**Category:** Questions\
**Tags:** engineering\
**Created:** [July 9, 2015, 3:24pm UTC](https://community.wolfram.com/t/multiplying-lists/6121 "2015-07-09T15:24:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lashofer1](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/lashofer1/32/15981_2.png) [@lashofer1](https://community.wolfram.com/u/lashofer1)\
**Post date:** [July 9, 2015, 3:24pm UTC](https://community.wolfram.com/t/multiplying-lists/6121/1 "2015-07-09T15:24:05Z")

</div>

Given the two lists; how do you multiply them?  
L1 = {{X1 , y1}, {X2 , y2}, {X3 , y3}, {X4, y4},…,{Xn, yn}}  
L2 = {{X1 , z1}, {X2 , z2}, {X3 , z3}, {X4, z4},,{Xn, zn}}  
To obtain:  
L1_L2 = {{ X1 , y1_ z1}, { X2 , y2\* z2}, { X3 , y3\* z3}, { X4 , y4\* z4},},{Xn, yn\*zn}

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [July 9, 2015, 6:17pm UTC](https://community.wolfram.com/t/multiplying-lists/6121/2 "2015-07-09T18:17:09Z")

</div>

It looks like X1, X2 etc are indexes or keys of some kind… is that right? You’re using a list like a dictionary-like data structure. If that’s the case you probably want to use Associations instead of lists. Associations are the correct datastructure for this situation. You can solve this issue with Merge:

```
Merge[{<|a -> 1, b -> 2|>, <|a -> 4, b -> 5|>}, Apply[Times]]

```

Here “a” and “b” are the keys. We merge them and Apply Times.

For lists, it’s not clear how you want to handle edge cases, but you can do the following:

```
Transpose[{L1[[All, 1]], L1[[All, 2]]*L2[[All, 2]]}]

{{X1, y1 z1}, {X2, y2 z2}, {X3, y3 z3}, {X4, y4 z4}}

```

I’ll let you put together how that works.

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [July 9, 2015, 6:29pm UTC](https://community.wolfram.com/t/multiplying-lists/6121/3 "2015-07-09T18:29:07Z")

</div>

I

```
n[52]:= L1 = {{X1, y1}, {X2, y2}, {X3, y3}, {X4, y4}}
 L2 = {{X1, z1}, {X2, z2}, {X3, z3}, {X4, z4}} 

Out[52]= {{X1, y1}, {X2, y2}, {X3, y3}, {X4, y4}}

Out[53]= {{X1, z1}, {X2, z2}, {X3, z3}, {X4, z4}}

```

will do it. regards

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [July 9, 2015, 6:29pm UTC](https://community.wolfram.com/t/multiplying-lists/6121/4 "2015-07-09T18:29:48Z")

</div>

sorry. missed the answer:

```
In[57]:= Transpose[{Transpose[L1][[1]], 
  Transpose[L1][[2]] Transpose[L2][[2]]}]

Out[57]= {{X1, y1 z1}, {X2, y2 z2}, {X3, y3 z3}, {X4, y4 z4}}

```

---

<div class="post-metadata">

**Author:** ![lashofer1](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/lashofer1/32/15981_2.png) [@lashofer1](https://community.wolfram.com/u/lashofer1)\
**Post date:** [July 10, 2015, 11:11pm UTC](https://community.wolfram.com/t/multiplying-lists/6121/5 "2015-07-10T23:11:10Z")

</div>

Can this result be extended for “n” elements as:

Given the two lists; how do you multiply them?  
L1 = {{X1 , y1}, {X2 , y2}, {X3 , y3}, {X4, y4},…,{Xn, yn}}  
L2 = {{X1 , z1}, {X2 , z2}, {X3 , z3}, {X4, z4},,},{Xn, zn}}  
To obtain:  
L1_L2 = {{ X1 , y1_ z1}, { X2 , y2\* z2}, { X3 , y3\* z3}, { X4 , y4\* z4},},{Xn, yn\*zn}

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [July 11, 2015, 6:05am UTC](https://community.wolfram.com/t/multiplying-lists/6121/6 "2015-07-11T06:05:11Z")

</div>

Yes. Just try it.

But note, the code given by Sean Clarke,

```
Transpose[{L1[[All, 1]], L1[[All, 2]]*L2[[All, 2]]}]

```

which is basically the same, looks a bit mor elegant.

Regards HD

---

<div class="post-metadata">

**Author:** ![lashofer1](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/lashofer1/32/15981_2.png) [@lashofer1](https://community.wolfram.com/u/lashofer1)\
**Post date:** [July 11, 2015, 9:25pm UTC](https://community.wolfram.com/t/multiplying-lists/6121/7 "2015-07-11T21:25:27Z")

</div>

I tried it for “n=500” and it worked. I was just unsure. Many thanks !!!

You always a good job
