Skip to main content

Operate on several lists to create one list



How do you put corresponding values from different lists together according to some operation?


E.g. I have three lists giving the velocity in the x, y and z direction respectively. I'd like create one list giving the 2-norm, $\sqrt{x^2+y^2+z^2}$.


I would be able to do it procedurally by using for example MapIndexed on one of the lists toghether with Part, I suppose. But I'd like to know if there is a more elegant solution.



Answer



The general way to do this is using MapThread. Using your norm example,


MapThread[Norm[{##}]&, {listX, listY, listZ}]

This particular example has easier solutions though:


Sqrt[ listX^2 + listY^2 + listZ^2 ]

Comments