如何将 3 维元组转换为数组
a = []
a.append((1,2,4))
a.append((2,3,4))
在一个数组中:
b = [1,2,4,2,3,4]
最佳答案
使用 list comprehension :
>>> a = []
>>> a.append((1,2,4))
>>> a.append((2,3,4))
>>> [x for xs in a for x in xs]
[1, 2, 4, 2, 3, 4]
使用 itertools.chain.from_iterable
:
>>> import itertools
>>> list(itertools.chain.from_iterable(a))
[1, 2, 4, 2, 3, 4]
关于Python将元组转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20637970/