本文介绍了并行算术?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 给定a和b,两个相等长度的整数列表,我希望c为 [a1-b1,a2-b2,...,an-bn]。我可以这样做: c = [0] * len(a) 为ndx,项目为枚举(a): c [ndx] = item - b [ndx] 但我想知道是否有更好的方法,或许可以避免循环? 尼克。 (我似乎记得从我遥远的过去,这种事情已经死了 轻松使用APL .. .c = ab,或多或少。) N 解决方案 c = [a [i] - b [i] for x in xrange(len(a))] Terrance N. Phillip写道: 这里''一种方式: c = [a_item - b_item为a_item,b_item为zip(a,b)] 和另一个: 导入运算符 c = map(operator.sub,a,b) - 迈克尔霍夫曼 Given a and b, two equal length lists of integers, I want c to be[a1-b1, a2-b2, ... , an-bn]. I can do something like:c = [0] * len(a)for ndx, item in enumerate(a):c[ndx] = item - b[ndx]But I''m wondering if there''s a better way, perhaps that avoids a loop?Nick.(I seem to recall from my distant past that this sort of thing was deadeasy with APL... c = a-b, more or less.)N 解决方案c = [a[i] - b[i] for i in xrange(len(a))]Here''s one way:c = [a_item - b_item for a_item, b_item in zip(a, b)]And another:import operatorc = map(operator.sub, a, b)--Michael Hoffman 这篇关于并行算术?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-12 10:43