So I am trying to print out a table using the map function. My code looks like this:
parameters = Table[{a, z}, {a, 1.251,2.5,5.251}, {z, {1, 10, 15, 25, 30}}];
Map[r+a+z &, parameters, {2}]
Unfortunately, this gets me a list with the parameters unchanged. What I want is for this function to return a list of the sort {r+1.251+1},{r+1.251+10},{r+1.251+15}...{r+2.5+1},{r+2.5+10},{r+2.5+15}...
etc etc
Obviously in the final output, the numbers would actually be added up.
Map[({r + #[[1]] + #[[2]]}) &, Flatten[parameters, 1]]
$\endgroup$Map[Plus[r, Total@#] &, parameters, {2}]
$\endgroup$Map[r + Total[#] &, First@parameters]
The hash mark stands for the argument; the ampersand is postfix forFunction
. See the documentation forFunction
. $\endgroup$a
andz
are not stored or remembered in any way as references to anything inparameters
. Another neat way to solve your problem would beTotal[parameters, {3}] + r
. Further reading is already covered in other comments $\endgroup$