Python将两个数组合并成一个数组,多维数组变成一维数组

1.extend方法

c1 = ["Red","Green","Blue"]
c2 = ["Orange","Yellow","Indigo"]
c1.extend(c2)
c1 == ["Red","Green","Blue","Orange","Yellow","Indigo"]

2.直接相加

c1 = ["Red","Green","Blue"]
c2 = ["Orange","Yellow","Indigo"]
c3 = c1 + c2
c3 == ["Red","Green","Blue","Orange","Yellow","Indigo"]

3.flatten

a = [[1,3],[2,4],[3,5]]
a = array(a)
a.flatten()
array([1, 3, 2, 4, 3, 5])
©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页