处理多个数组值

时间:2013-12-20 01:29:37

标签: python

我正在创建一个newArrayList。每个signalxOP数组减去渐变,并且每个applyFieldOP数组都有多个。 (SignalxOP[] - Gradient) * appliedFieldOP[]

我该怎么做?以下是我尝试过的方法。它一直给我错误。

signalxOP = [5,4,3,2,1]
appliedFieldOP= [1,0.5,0,-0.5,-1]
Gradient = 1.5

newList = [[(x-Gradient)*y] for x,y in signalxOP,appliedFieldOP]
py.plot(appliedFieldOP,newList)
py.show()

错误显示

newList = [[(x-Gradient)*y] for x,y in signalxOP,appliedFieldOP]
ValueError: too many values to unpack

1 个答案:

答案 0 :(得分:3)

您可以使用zip功能,就像这样

newList = [[(x-Gradient)*y] for x,y in zip(signalxOP,appliedFieldOP)]