[問題] 關於多個矩陣進行合併消失

看板Python作者時間7年前 (2018/09/10 17:21), 7年前編輯推噓0(003)
留言3則, 1人參與, 最新討論串1/1
我現在有很多個矩陣 分別命名為A_1、A_2、A_3、A_4、A_5......... 我想要利用for迴圈經他們一次合併在一起 但是不太曉得要怎麼寫 這是我的程式碼 ======================= import numpy as np A_1 = np.array([1,2,3]) A_2 = np.array([4,5,6]) A_3 = np.array([7,8,9]) A_4 = np.array([10,11,12]) A_5 = np.array([13,14,15]) for n in range (1,5): C = np.hstack(("A_%s" %n)) D=np.hstack((A_1,A_2,A_3,A_4,A_5)) print(C) print("-----") print(D) 執行結果為: ['A' '_' '4'] ----- [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] =================== 我希望我的C的結果和D一樣 想請問for迴圈的部分要怎麼改才對? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.105.133.228 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1536571300.A.EDA.html

09/10 17:30, , 1F
for n in range (1,5):
09/10 17:30, 1F

09/10 17:31, , 2F
print("A_{}".format(n))
09/10 17:31, 2F

09/10 17:31, , 3F
執行完你應該就知道了
09/10 17:31, 3F
還是不怎麼清楚QQ 可以再詳細點嗎TT ※ 編輯: st40182 (120.105.133.228), 09/10/2018 19:39:33 阿沒事 我想到了XD ※ 編輯: st40182 (120.105.133.228), 09/10/2018 19:43:44
文章代碼(AID): #1RbZUaxQ (Python)