# Divide two 2D arrays element vise

I have two 2D list

list1 = {{x,a1},{y,a2},{z,a3}}
list2 = {{x,b1},{y,b2},{z,b3}}


I want a list that divides only the second element of each element of the 2D array.

list3 = {{x,a1/b1},{y,a2/b2},{z,a3/b3}}


I know how to do this using a loop, but I want to know is there an elegant way using mathematica?

• Some options: MapThread[{First[#1], Last[#1]/Last[#2]} &, {list1, list2}] or Thread[{list1[[All, 1]], list1[[All, 2]]/list2[[All, 2]]}] Mar 3, 2022 at 14:16
• list1/{1, Last@#} & /@ list2
– Syed
Mar 3, 2022 at 14:16
• list1/(ReplacePart[#, 1 -> 1] & /@ list2) Mar 3, 2022 at 14:19
• @Syed - you are missing parentheses around denominator, i.e., list1/({1, Last@#} & /@ list2) Mar 3, 2022 at 14:20
• Thanks @BobHanlon: It is always a good idea to have parentheses. Is it not evaluating on your machine, as I see this.
– Syed
Mar 3, 2022 at 14:24

list3 = list1;
list3[[All, 2]] = list3[[All, 2]]/list2[[All, 2]];
list3

{{x, a1/b1}, {y, a2/b2}, {z, a3/b3}}


Also

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

{{x, a1/b1}, {y, a2/b2}, {z, a3/b3}}


and

SubsetMap[# / list2[[All, 2]]&, list1, {All, 2}]

{{x, a1/b1}, {y, a2/b2}, {z, a3/b3}}