[問題] 刪除大量數據的速度問題

看板Python作者 (St. Ba)時間10年前 (2015/11/05 15:11), 10年前編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/2 (看更多)
想請問一下 我想從x, y兩個元素數量相等list當中,刪除所有值為-9999的項, 並且另一list同index的項目也要刪除,但因為list中大概有180萬筆, -9999的聯集數量大概57萬筆,該如何加速以下的程序呢? def get_index(a): lst = [i for i, j in enumerate(a) if j == -9999] return lst indx = get_index(x) indy = get_index(y) indlst = list(set(indx) | set(indy)) xlst = [j for i, j in enumerate(x) if i not in indx] ylst = [j for i, j in enumerate(y) if i not in indy] -- Sent from my Android -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.122.53.22 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1446707507.A.1AC.html ※ 編輯: stba5328 (140.122.53.22), 11/05/2015 15:12:29

11/05 15:23, , 1F
get_index()跟xlst = ... 不是在做同一件事嗎?
11/05 15:23, 1F
文章代碼(AID): #1MEm4p6i (Python)
文章代碼(AID): #1MEm4p6i (Python)