Can somebody explain the following behaviour of “Thread” with multiple arguments:
Consider:
t= {{a,b},{c,d}};
Thread[ t[[{1,2},{1,2}]] ]
I expected an answer of: {a,d}, but I get: {{a, c}, {b, d}}
This looks like the outer product!
The same happens with the explicite form of Part:
Thread[Part[ t, {1,2}, {1,2}] ]
On the other hand, MapThread works as expected:
MapThread[ t[[##]] &, {{1, 2}, {1, 2}} ]
gives {a,d}
Have I misunderstood the manual or is this a bug?
It’s the order of evaluation. t[[{1, 2}, {1, 2}]] evaluates as List[{a,b},{c,d}], and Thread[List[{a,b},{c,d}]] gives {List[a,c],List[b,d]}. To get what you want you must reverse the order of evaluation, for example this way:
t = {{a, b}, {c, d}};
Thread[f[{1, 2}, {1, 2}]] /. f -> (t[[##]] &)
Thank you for you answer.
I learned from this, that care must be taken with “Thread”, because Thread does not have the attribute “HoldFirst”.
This problem does not appear with MapThread because here the Arguments are separate.