I am interested in finding the most concise elegant way of doing the following: We have a function fun[x1,x2] and two lists:




I want my result to be:


Thanks for help.

  • 1
    $\begingroup$ Table[{i, func[i, j]}, {i, ls1}, {j, ls2}] $\endgroup$
    – matrix42
    Commented Nov 16, 2017 at 5:08

1 Answer 1


Well, that's an easy one to write and maybe a bit harder to understand:

ls1 = {a1, a2, a3, a4};
ls2 = {b1, b2, b3, b4};

Outer[{#1, func[##]} &, ls1, ls2]

Mathematica graphics

  • $\begingroup$ this works as well Outer[{#, func[##]} &, ls1, ls2] $\endgroup$ Commented Nov 16, 2017 at 12:40
  • $\begingroup$ @José I wonder what you wanted to say by that. $\endgroup$
    – LLlAMnYP
    Commented Nov 20, 2017 at 15:09
  • $\begingroup$ Oh, no need of adding ‘1’ to ‘#’, nothing special. $\endgroup$ Commented Nov 20, 2017 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.