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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM