# Multiply each element of second position of two list

If I have two list such as:

list1 = {{40., 7.50551*10^-10}, {40.,7.50557*10^-10}, {40.,7.50566*10^-10},
{40.0001, 7.50578*10^-10}, {40.0001, 7.50591*10^-10},{40.0001, 7.50607*10^-10},
{40.0002, 7.50625*10^-10}, {40.0002, 7.50645*10^-10},{40.0003, 7.50668*10^-10},
{40.0003, 7.50692*10^-10}};

list2 = {{40., 0.0712996}, {40., 0.0712996}, {40.,0.0712996}, {40.0001, 0.0712996},
{40.0001, 0.0712996}, {40.0001, 0.0712996}, {40.0002, 0.0712996},
{40.0002, 0.0712996}, {40.0003, 0.0712996}, {40.0003, 0.0712996}};


where the first element of both lists is the same. How can I multiply each second element of each list by each other while keeping the first element intact to obtain a list with the same elements of the first position and the multiplication of each element of the second position?

## 4 Answers

Here is one way:

{list1[[All, 1]], (list1 list2)[[All, 2]]} // Transpose

• Thank you! This works great !
– John
May 24 '20 at 22:26

The same, but with Thread.

Thread[{list1[[All, 1]], list2[[All, 2]]*list1[[All, 2]]}]


Another way to get the product is

Table[list2[[i, 2]]*list1[[i, 2]], {i, 1, Length[list1]}]


Here is my version:

MapThread[{#[[1]], #[[2]] #2[[2]]} &, {list1, list2}]

list1 Inner[{#2,#1}&,list2,{0,1}, #2&]


In the example given by the OP (but not in the general case of the question title), all the second elements in list2 are also identical, and Dot may be used to 'multiply a matrix column by a factor', and get the same result:

list1.{{1,0},{0,list2[[1,2]]}}


And:

(list1 Inner[{#2,#1}&,list2,{0,1}, #2&])===(list1.{{1,0},{0,list2[[1,2]]}})


True

Yet another method is the following:

list1 ArrayFlatten[{{1, List/@list2[[All,2]]}}]


For this use of ArrayFlatten see this old SO answer by Janus

Original Answer

 list1 Inner[{1,#1}&,list2,{1,0}, #2&]

• Correct. I had noticed that the first elements for both lists are the same, but had not noticed the second elements of list 2. I can only suppose that the OP is asking for a general example. May 25 '20 at 11:27