作者yowantl (加油)
看板Python
標題[問題] np.zeros memory error
時間Thu Apr 19 12:04:24 2018
如標題 以下是我的code
出現下面錯誤
ML_CROSS
Traceback (most recent call last):
File "D:\Curry\DCIM\lab1\FINAL2\ML.py", line 27, in <module>
designM=np.zeros((Train,M))
MemoryError
>>>
請問大大 該如何解
謝謝
***************************
import csv
import math
import numpy as np
print " ML_CROSS "
Train=35000
Verif=5000
M=6400
D=80
s1=100
s2=100
pos=13.5
dim=0
lam=0
dim_cross=1
coordinate=[]
target=[]
#init_a = np.zeros((10000*10000),4096),np.dtype='float16'))
target_v=np.zeros(Verif)
target_t=np.zeros(Train)
designM=np.zeros((Train,M))
*****************************************
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.163.0.31
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1524110667.A.950.html
→ gmccntzx1: 記憶體不足. designM有35000*6400*8(byte)=1.792e9 04/19 12:42
→ gmccntzx1: (byte) 約1.67GB... 04/19 12:43
→ gmccntzx1: (np.zeros的dtype預設是np.float64) 04/19 12:44
→ yowantl: 那請問 有甚麼解法嗎 04/19 13:48
→ yowantl: 而且我這邊記憶體是32GB 04/19 14:14
→ gmccntzx1: 先試著改用np.float32或np.float16看看 04/19 14:25
→ gmccntzx1: 因為你的code看起來就是要這麼大的陣列 04/19 14:26
推 gmccntzx1: 另外可以試試用memory_profiler確認,看執行到designM這 04/19 14:29
→ gmccntzx1: 行前,已經用掉多少記憶體了 04/19 14:29
→ gmccntzx1: 再不然,可能要改存成sparse matrix的方式去計算 04/19 14:31