在做机器学习时,两个二维数组嵌套在一个数组内,现想将其解嵌套出来,尝试了循环迭代,在面对大数据量时效率不高,
a = np.arange(10).reshape([2,5]) b = np.arange(10).reshape([1,10]) c = np.array((a,b)) c
输出
array([array([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9]]), array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])],
dtype=object)
问题解决:
使用itertools 中的chain工具进行解迭代
d = list(chain.from_iterable(c)) e = list(chain.from_iterable(d)) e
输出
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
再将其重新改变成自己想要的形状就好了



