[問題] 大量命名問題

看板Python作者 (小刀會序曲)時間6年前 (2018/11/21 22:40), 編輯推噓1(108)
留言9則, 4人參與, 6年前最新討論串1/1
大家好,想要改善以下程式,讓它漂亮一點但不知道怎麼寫 str1=('D:/ANN/training/0/*png','D:/ANN/training/1/*png', 'D:/ANN/training/2/*png','D:/ANN/training/3/*png', 'D:/ANN/training/4/*png') coll0 = io.ImageCollection(str1[0]) mat0 = io.concatenate_images(coll0) coll1 = io.ImageCollection(str1[1]) mat1 = io.concatenate_images(coll1) coll2 = io.ImageCollection(str1[2]) mat2 = io.concatenate_images(coll2) coll3 = io.ImageCollection(str1[3]) mat3 = io.concatenate_images(coll3) coll4 = io.ImageCollection(str1[4]) mat4 = io.concatenate_images(coll4) 不知道這段程式該如何改善?有查到要用dict,但還是不知道如何使用 資料裡面都是PNG檔,謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.126.194.162 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1542811223.A.490.html

11/21 23:52, 6年前 , 1F
感覺用迴圈加陣列比較好吧
11/21 23:52, 1F

11/22 01:42, 6年前 , 2F

11/22 14:14, 6年前 , 3F
謝謝兩位
11/22 14:14, 3F

11/22 17:02, 6年前 , 4F
coll = {}
11/22 17:02, 4F

11/22 17:02, 6年前 , 5F
for i in range(5):
11/22 17:02, 5F

11/22 17:03, 6年前 , 6F
coll[i] = io.ImageCollection(strl[i])
11/22 17:03, 6F

11/22 17:03, 6年前 , 7F
mat[i] = io.concatenate_images(coll[i])
11/22 17:03, 7F

11/22 17:04, 6年前 , 8F
前面還有一個 mat ={} 忘了放
11/22 17:04, 8F

11/22 17:04, 6年前 , 9F
用dict 存放的版本
11/22 17:04, 9F
文章代碼(AID): #1RzMvNIG (Python)
文章代碼(AID): #1RzMvNIG (Python)