至少在过去 8 年中,Wolfram Research 已经为该函数提供了相同的文档:
Thread[f[args]]
“线程” f 出现在 args 中的任何列表上。
如果我见过一个可爱的圆形定义。
有谁知道实际的语义是什么并且可以提供非循环的正确解释?
最佳答案
它的工作原理类似于 Python 的 zip()
功能,但以更一般的方式。例如:
In[1] := Thread[{{1, 2, 3}, {4, 5, 6}}] (* f == List *)
Out[1] = {{1, 4}, {2, 5}, {3, 6}}
In[2] := Thread[f[{1, 2, 3}, {4, 5, 6}]]
Out[2] = {f[1, 4], f[2, 5], f[3, 6]}
In[3] := Thread[f[a+b+c, d+e+f], Plus]
Out[3] = f[a, d] + f[b, e] + f[c, f]
关于functional-programming - Mathematica 的 Thread 函数的语义,最终需要有人把它搁置一旁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1250125/