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])

猜你喜欢

转载自www.cnblogs.com/shiluoliming/p/9075693.html