So much thanks to Szabolcs in improving sequence.. for complete explanation. I am so glad to read all explanation which fundamentally remove the problem. But in number 4 of its explanation pointed to Apply in {1} level
: As we show with @@@
. But I have a problem with this function. As Szabolcs pointed, this function acts as:
list = {{x1,y1}, {x2,y2}, ..., {xn,yn}},
f@@@list= {f[x1,y1], f[x2,y2], ..., f[xn,yn]}
But for example we want to use Last
for a list as:
m = {{1, 2, I}, {0, 0, 0}, {I, I, 3}, {2, 6, I}, {0, 0, 0}, {0, 0, 0}, {1, 6, 4}, {0, 0, 0}, {1, 4, 5}}
Last@m
{1, 4, 5}
Apply[Last, {m}]= Last@@{m}
{1, 4, 5}
Last /@ m
{I, 0, 3, I, 0, 0, 4, 0, 5}
But Apply[Last, {m}, {1}]
or Last@@@{m}
doesn't have any result. I predicted that I should have Last@@@ {m}={Last{1, 2, I},Last{0,0,0},....}
which is the result of Last/@ m
.
Also I can't understand what is the exact differnce between Last@m
and Last@@{m}
. I have confused with these syntax.
@@@
supplies a sequence to the function being applied, withn
slots wheren
is the length of the sublists you're mapping over.Last
takes a list as an argument, so you needLast/@m
, for understanding, the way to make@@@
work is to doLast[List@##]&@@@m
, but that's just tearing the list apart and putting it back together. $\endgroup$@@@
andf/@{{x1,y1},{x2,y2}}
, which gives{f[{x1,y1}],f[{x2,y2}]}
$\endgroup$Apply
orMap
. I should have mentioned in my answer thatMap
tends to be quite a bit faster thanApply
. I still useApply
a lot in the exact same way I described, but for the times when performance is important, you should know thatApply
tends not to be as fast asMap
. $\endgroup$MapThread[f,{a,b}]===f@@@Transpose[{a,b}]
whena
andb
are lists of equal length. I mentally think ofMapThread
aszipWith
from Haskell. $\endgroup$