本文介绍了Mathematica的Thread函数的语义,有人需要最终把这个休息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 至少在过去的8年里,Wolfram Research已经为这个功能提供了相同的文档: Thread [f [args ]] threadsf显示在参数列表中。 一个可爱的循环定义,如果我见过一个。 有人知道实际的语义是什么,并且可以提供适当的解释是非圆形的?解决方案线程有点像泛化 zip 来自其他函数式语言。 对于简单的情况,您示例中的所有参数元素都是列表, 线程[f [args]] 相当于 f @@@转置[{args}] ,如文档中前两个示例所示。主要的缺点是当你的参数不是列表时,在这种情况下,它们会被有效地克隆出来;例如, 线程[g [{a,b},c,{d,e},f]] 相当于 g [#1,c,#2,f]& @@@ Transpose [{{a,b},{d,e}}] 找到自己使用线程来构造规则列表或方程列表。 Wolfram Research has had the same documentation for this function for the last 8 years at least:Thread[f[args]]"threads" f over any lists that appear in args.A lovely circular definition if I've ever seen one.Does anyone know what the actual semantics are and can provide a proper explanation that is non-circular? 解决方案 Thread is a bit like a generalization zip from other functional languages.For simple cases, where all the elements of args from your example are lists, Thread[f[args]]is equivalent to f @@@ Transpose[{args}]as shown in the first couple examples in the documentation. The major wrinkle is when you have args that are not lists, in which case they're effectively curried out; for example,Thread[g[{a, b}, c, {d, e}, f]]is equivalent to g[#1, c, #2, f]& @@@ Transpose[{{a, b}, {d, e}}]I usually find myself using Thread to construct lists of rules or lists of equations. 这篇关于Mathematica的Thread函数的语义,有人需要最终把这个休息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 20:23