1def flatten(L):
2 for item in L:
3 try:
4 yield from flatten(item)
5 except TypeError:
6 yield item
7
8list(flatten([[[1, 2, 3], [4, 5]], 6]))
9>>>[1, 2, 3, 4, 5, 6]
10
1>>> a = np.array([[1,2], [3,4]])
2>>> a.flatten()
3array([1, 2, 3, 4])
4>>> a.flatten('F')
5array([1, 3, 2, 4])