, , :
imort numpy as np
structure = [[np.array([[1, 2, 3], [4, 5, 6]]), np.array([[7, 8, 9], [10, 11, 12]])],
[np.array([[13, 14, 15], [16, 17, 18]]), np.array([[19, 20, 21], [22, 23, 24]])]]
from itertools import chain
zipped = (zip(*ele) for ele in zip(*next(zip(*structure))))
print (list(chain.from_iterable(zip(*zipped))))
[(1, 13), (4, 16), (2, 14), (5, 17), (3, 15), (6, 18)]
, :
In [4]: start = zip(*structure)
In [5]: start
Out[5]:
[(array([[1, 2, 3],
[4, 5, 6]]), array([[13, 14, 15],
[16, 17, 18]])), (array([[ 7, 8, 9],
[10, 11, 12]]), array([[19, 20, 21],
[22, 23, 24]]))]
In [6]: first_col = next(start)
In [7]: first_col
Out[7]:
(array([[1, 2, 3],
[4, 5, 6]]), array([[13, 14, 15],
[16, 17, 18]]))
In [8]: intersting_pairs = zip(*first_col)
In [9]: intersting_pairs
Out[9]:
[(array([1, 2, 3]), array([13, 14, 15])),
(array([4, 5, 6]), array([16, 17, 18]))]
In [10]: create_final_pairings = [zip(*ele) for ele in intersting_pairs]
In [11]: create_final_pairings
Out[11]: [[(1, 13), (2, 14), (3, 15)], [(4, 16), (5, 17), (6, 18)]]
, :
In [13]: from itertools import chain
In [14]: flat_list = list(chain.from_iterable(zip(*create_final_pairings))
In [15]: flat_list
Out[15]: [(1, 13), (4, 16), (2, 14), (5, 17), (3, 15), (6, 18)]
zip :
In [17]: l = [[1,2,3],[4,5,6]]
In [18]: zip(*l)
Out[18]: [(1, 4), (2, 5), (3, 6)]
In [19]: zip(*l)[0]
Out[19]: (1, 4)
In [20]: zip(*l)[1]
Out[20]: (2, 5)
In [21]: zip(*l)[2]
Out[21]: (3, 6)
python2 itertools.izip:
from itertools import chain, izip
zipped = (izip(*ele) for ele in izip(*next(izip(*structure))))
print (list(chain.from_iterable(izip(*zipped))))
[(1, 13), (4, 16), (2, 14), (5, 17), (3, 15), (6, 18)]