我想在数据下方压缩,但是我得到TypeError:zip参数#1必须支持迭代。 我已经表明了预期的结果 有没有人可以帮助我?感谢。
nn_inputs = []
for speed, occupancy, capacity in zip(speed, occupancy,capacity):
nn_input = zip(int(speed),int(occupancy), float(capacity))
nn_inputs.append(nn_input)
print nn_inputs
Data input:
speed = [-24 , -15 , -9 ]
occupancy = [15, 3, 4]
capacity = [1.47056441941, 2.12024661067, 2.47288942169 ]
Expected result:
[-24, 15 , 1.47056441941]
[-15, 3 , 2.12024661067]
[-9 , 4 , 2.47288942169]
答案 0 :(得分:0)
只需使用zip
一次:
>>> speed = [-24 , -15 , -9 ]
>>> occupancy = [15, 3, 4]
>>> capacity = [1.47056441941, 2.12024661067, 2.47288942169 ]
>>> nn_inputs = zip(speed, occupancy, capacity)
>>> nn_inputs
[(-24, 15, 1.47056441941), (-15, 3, 2.12024661067), (-9, 4, 2.47288942169)]
结果是元组列表;如果你想要列表,你可以做
>>> nn_inputs = map(list, zip(speed, occupancy, capacity))
>>> nn_inputs
[[-24, 15, 1.47056441941], [-15, 3, 2.12024661067], [-9, 4, 2.47288942169]]