I have a function

f[x_,y_,z_]:= a^x b^y c^z

and I want to evaluate it for various values of x,y,z always coming in triples. This means I have a database with columns x,y,z and rows vectors say A,B,C. (Sorry I could not write a Latex table here for some reason!)

How does one create such a table on Mathematica and then asks the function to directly compute 1) f[vector A] instead f[x,y,z] and 2) say the sum or product of vectors A,B, and C?

  • $\begingroup$ E.g. f @@ {X, Y, Z} - see Apply $\endgroup$
    – corey979
    Jan 18, 2018 at 17:01
  • 1
    $\begingroup$ I believe you would be best served either with Dataset, which has a convenient (and I think optimized) Query syntax, or with Association, from which you can Lookup. That said, there are probably a dozen different ways to get this done. $\endgroup$
    – b3m2a1
    Jan 18, 2018 at 17:06
  • $\begingroup$ You can use \begin{bmatrix} ... \end{bmatrix} if you want to draw a table with mathjax. $\endgroup$
    – anderstood
    Jan 18, 2018 at 18:48
  • 1
    $\begingroup$ The title mentions a database, and the answer below describes how to make a Dataset, but the question seems to be only about how to apply a function to a list of vectors. For this all you need is f @@@ {A,B,C}. Don't make a Dataset if you don't plan to use the querying functionality. $\endgroup$
    – Jason B.
    Jan 19, 2018 at 19:34

1 Answer 1


I recommend looking into Dataset.

Here is a test dataset:

data = Dataset@
  Table[<|"x" -> RandomReal[], "y" -> RandomReal[], 
    "z" -> RandomReal[]|>, {i, 9}]

Then you can apply your function like this:

f[data[1, "x"], data[1, "y"], data[1, "z"]]

or shorter:

f @@ data[1]

Which applies your function to the first row (or row vector A in your question).

With a dataset you can use Total like this to get a sum per row:

data[1, Total]

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.