numpy - How to transpose a 3D list in python? -
let's have matrix m
of dimensions 9 x 9 x 26:
[[['a00', ... 'z00'], ['a01', ... 'z01'], ... ['a09', ... 'z09']], [['a10', ... 'z10'], ['a11', ... 'z11'], ... ['a19', ... 'z19']], ... [['a90', ... 'z90'], ['a91', ... 'z91'], ... ['a99', ... 'z99']]]
i want convert following matrix of dimensions 26 x 81:
[['a00', 'a01', ... 'a09', 'a10', ... 'a19', ... 'a99'], ['z00', 'z01', ... 'z09', 'z10', ... 'z19', ... 'z99']]
what's best way of doing in python?
if have list , not numpy array:
m = [[['a00', 'z00'], ['a01', 'z01'], ['a09', 'z09']], [['a10', 'z10'], ['a11', 'z11'], ['a19', 'z19']], [['a90', 'z90'], ['a91', 'z91'], ['a99', 'z99']]] itertools import chain print zip(*(chain(*m)) [('a00', 'a01', 'a09', 'a10', 'a11', 'a19', 'a90', 'a91', 'a99'), ('z00', 'z01', 'z09', 'z10', 'z11', 'z19', 'z90', 'z91', 'z99')]
Comments
Post a Comment