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

1.extend方法

c1 = ["Red","Green","Blue"]
c2 = ["Orange","Yellow","Indigo"]
c1.extend(c2)
c1 == ["Red","Green","Blue","Orange","Yellow","Indigo"]
  • 1
  • 2
  • 3
  • 4

2.直接相加

c1 = ["Red","Green","Blue"]
c2 = ["Orange","Yellow","Indigo"]
c3 = c1 + c2
c3 == ["Red","Green","Blue","Orange","Yellow","Indigo"]
  • 1
  • 2
  • 3
  • 4

3.flatten

a = [[1,3],[2,4],[3,5]]
a = array(a)
a.flatten()
array([1, 3, 2, 4, 3, 5])
posted @ 2018-05-23 10:41  失落的黎明  阅读(78699)  评论(0编辑  收藏  举报