1
$\begingroup$

Been working on this for hours, but I can't seem to find something which mimics this.

So I've got parameter values in a list of the form:

parameters=
{{{-2, 0.5}, {-2, 1}, {-2, 2}, {-2, 3}, {-2, 4}}, 
{{-1, 0.5}, {-1,  1}, {-1, 2}, {-1, 3}, {-1, 4}}, 
{{0, 0.5}, {0, 1}, {0, 2}, {0,3}, {0, 4}},
{{1, 0.5}, {1, 1}, {1, 2}, {1, 3}, {1, 4}},
{{2,0.5}, {2, 1}, {2, 2}, {2, 3}, {2, 4}}}

I've got a MapThread function:

MapThread[f, parameters, 1]

which gives

{f[{-2, 0.5}, {-1, 0.5}, {0, 0.5}, {1, 0.5}, {2, 0.5}], 
f[{-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}], 
f[{-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}], 
f[{-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}], 
f[{-2, 4}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}]}

When I actually want it to give:

{{f[-2, 0.5], f[-1, 0.5], f[0, 0.5], f[1, 0.5], f[2, 0.5] }, 
{f[-2, 1], f[-1, 1], f[0, 1], f[1, 1], f[2, 1]}, 
{f[[-2, 2], f[-1, 2], f[0, 2], f[1, 2], f[2, 2]}, 
{f[-2, 3], f[-1, 3], f[0, 3], f[1, 3], f[2, 3]}, 
{f[-2, 4], f[-1, 4], f[0, 4], f[1, 4], f[2, 4]}}

Not quite sure what is going wrong.

I am especially interested in how to work with the curly brackets. Thanks in advance!

$\endgroup$
0
$\begingroup$
MapThread[f @@@ {##} &, parameters]

{{f[-2, 0.5], f[-1, 0.5], f[0, 0.5], f[1, 0.5], f[2, 0.5]},
{f[-2, 1], f[-1, 1], f[0, 1], f[1, 1], f[2, 1]},
{f[-2, 2], f[-1, 2], f[0, 2], f[1, 2], f[2, 2]},
{f[-2, 3], f[-1, 3], f[0, 3], f[1, 3], f[2, 3]},
{f[-2, 4], f[-1, 4], f[0, 4], f[1, 4], f[2, 4]}}

you get the same result using

f @@@ # & /@ Transpose[parameters]
$\endgroup$
0
$\begingroup$

Just Apply[] at an appropriate level before doing a Transpose[], so you don't need to Map[]:

Transpose[Apply[f, {{{-2, 0.5}, {-2, 1}, {-2, 2}, {-2, 3}, {-2, 4}},
                    {{-1, 0.5}, {-1, 1}, {-1, 2}, {-1, 3}, {-1, 4}},
                    {{0, 0.5}, {0, 1}, {0, 2}, {0, 3}, {0, 4}},
                    {{1, 0.5}, {1, 1}, {1, 2}, {1, 3}, {1, 4}},
                    {{2, 0.5}, {2, 1}, {2, 2}, {2, 3}, {2, 4}}}, {2}]]
   {{f[-2, 0.5], f[-1, 0.5], f[0, 0.5], f[1, 0.5], f[2, 0.5]},
    {f[-2, 1], f[-1, 1], f[0, 1], f[1, 1], f[2, 1]},
    {f[-2, 2], f[-1, 2], f[0, 2], f[1, 2], f[2, 2]},
    {f[-2, 3], f[-1, 3], f[0, 3], f[1, 3], f[2, 3]},
    {f[-2, 4], f[-1, 4], f[0, 4], f[1, 4], f[2, 4]}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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