Python zip函数及用法
zip() 函数是 Python 内置函数之一,它可以将多个序列(列表、元组、字典、集合、字符串以及 range() 区间构成的列表)“压缩”成一个 zip 对象。所谓“压缩”,其实就是将这些序列中对应位置的元素重新组合,生成一个个新的元组。
import numpy as np
my_list = [11,12,13]
my_tuple = (21,22,23)
my_tuple1 = (0,0,0)
print([x for x in zip(my_list,my_tuple, my_tuple1)])
#[(11, 21, 0), (12, 22, 0), (13, 23, 0)]
list_img_target = [(np.random.rand(2,3,2), (1)),
(np.random.rand(2,3,2), (2)),
(np.random.rand(2,3,2), (3))]
for x in zip(*list_img_target):
a = 0
# first tuple3, (np.random.rand(2,3,2), np.random.rand(2,3,2),np.random.rand(2,3,2))
#second tuple3 (1,2,3)
#same
batch = list(zip(*list_img_target))
c = 0
好记性不如烂键盘---点滴、积累、进步!