[問題] 大型矩陣相乘會卡很久

看板Python作者 (亨利王子)時間7年前 (2018/07/19 00:55), 7年前編輯推噓1(103)
留言4則, 2人參與, 7年前最新討論串1/1
大家好 我最近練習做 term-document-matrix 用到的 library是 : pandas sklearn 我的矩陣說起來並不會很大 大概 (55534, 3117) 數字再 0~503 之間(min,max) 不過我在做 相乘的時候 jupyter 都會卡很久就當掉了!!! 這行會卡很久 不知道問題會是出在哪裡呢? np.matmul(A,B) 底下是我的code 這個問題卡好久了QQ # ---------------- Code ----------------- # import import pandas as pd from sklearn.feature_extraction.text import CountVectorizer # 做 term-document-matrix vec = CountVectorizer() X = vec.fit_transform(contents_big_array) df = pd.DataFrame(X.toarray(), columns=vec.get_feature_names()) # 做矩陣 A = df.values.T B = df.values -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.45.101.55 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1531932953.A.86A.html

07/19 00:58, 7年前 , 1F
55534x55534的float可能會超出記憶體了
07/19 00:58, 1F

07/19 01:15, 7年前 , 2F
你記憶體多少....看一下記憶體是不是爆炸了
07/19 01:15, 2F
55534*55534*64bit 好像差不多 22G了耶OAO 可以問一下這種大型矩陣大概要怎麼算嗎? 還是可以分開運算在結合起來? ※ 編輯: HenryLiKing (140.138.25.124), 07/19/2018 09:55:57

07/19 10:04, 7年前 , 3F
term-document frequency 一定是 sparse matrix啊
07/19 10:04, 3F

07/19 10:06, 7年前 , 4F
直接拿X來乘不就好了嗎? 幹嘛轉array再轉dataframe?
07/19 10:06, 4F
文章代碼(AID): #1RJt4PXg (Python)
文章代碼(AID): #1RJt4PXg (Python)