📜  python将多维数组转换为一维 - Python代码示例

📅  最后修改于: 2022-03-11 14:46:06.538000             🧑  作者: Mango

代码示例2
# Python convert 2D into 1D array:

import itertools
x = [['foo'], ['bar', 'baz'], ['quux'], ("tup_1", "tup_2"), {1:"one", 2:"two"}]
print list(itertools.chain(*x))
print [element for sub in x for element in sub]

# Output:

['foo', 'bar', 'baz', 'quux', 'tup_1', 'tup_2', 1, 2]