ãã¼ã¿åæã«å½¹ç«ã¤ã¡ã¢ãªç®¡çã»åæ¸æ¹æ³
çããããã«ã¡ã¯
ãå
æ°ã§ãããæè¿èªçãå°ããã¤æã£ã¦ãã¾ããã
æ¬æ¥ã¯ãã¼ã¿åæã§ããèµ·ãããMemory Errorãã®å¯¾çãæ¸ãã¦ãããã¨æãã¾ãã
ä»åã®ã¯GPUã§ã¯ãªããCPUã§ãã
ãããããªããMemory Errorãã¨ééããã®ã
大éã®ãã¼ã¿ã解æããããããã¯ã大éã®ç¹å¾´éãæ±ãããã§ãã
ã¾ãã¯ãéä¸ã®å·¨å¤§éä¸å¦çãåå ã§è¼ããªããªã£ãã¨ãã§ããã
ãã®çµæããã·ã³ãè½ã¡ããã¨ããã¼ã¿åæãã¦ãã人ãé¥ããããããã¨ã§ãã
ãã®å ´åã®å¦æ¹ç®ãæ¸ãã¦ãããã¨æãã¾ãã
ã¡ã¢ãªå¯¾ç
ä¸è¦ãªå¤æ°ã®ã¡ã¢ãªãéæ¾ããã
ä¸çªã·ã³ãã«ã§ããããããªãããæ¶ãã¦ãã¾ãã¨ããæ¹å¼ã§ãã
æ¹æ³ã¯åç´ã§ããå¤æ°ãdelãã¦ãã¬ã¼ãã¸ã³ã¬ã¯ã·ã§ã³ï¼ä¸è¦ãªã¡ã¢ãªãååãã空ããæ¹å¼ï¼ãå®è¡ãããã¨ã§ãã
ä¾ãã°ã次ã®éãã§ãã
import gc import numpy as np matrix = np.random.rand((10000, 10000)) # é©å½ã«ä½æãã巨大è¡å # (å¦ç) del matrix #ä¸è¦ã«ãªã£ãã®ã§åé¤ gc.collect() # ã¬ã¼ãã¸ã³ã¬ã¯ã·ã§ã³ãå®è¡
ããã«ããè¦ããªããªã£ã段éã§ä¸è¦ãªå¤æ°ãåé¤ã§ãããããç¹ã«ã¡ã¢ãªãã®ãªã®ãªã®å ´åã«é常ã«ä¾¿å©ã§ãã
å¯è½ãªéãåã®ç²¾åº¦ãè½ã¨ã
numpyãpandasãå©ç¨ããã¨å¤§åã®ã«ã©ã ã¯float64ã«ãªã£ã¦ããã¨æãã¾ãã
ãããã解æããå ´åãfloat64ã§ä¿æããå¿
è¦ã¯ãªãã§ããããæ£ç´ãfloat32ãããã°ååã§ãã
ãã®ãããastypeãªã©ã§float32ããã以ä¸ã«ç¶æ³ã«å¿ãã¦åæ¸ããã°è¯ãã§ãã
åãå¤å®ããã¡ã¢ãªãåæ¸ããæ¹å¼ã¯æ¬¡ã®ç®æã«è¨è¼ããã¦ãã¾ãã
ã¾ããæ¨è«çµæãä¿åãããã¨æã£ããã¨ãããããã¾ãã
ãã®éã«ãã¼ã¿ãé常ã«å¤§ããã¨ãã£ã¹ã¯ãå§è¿«ãããã£ã¹ã¯ãã«ã®æ¦ãã¨ããä¸æ¯ãªãã¨ãè¡ããªããã°ãªãã¾ããã
ä¸ã¤ã®å¯¾çã¨ãã¦ä¿åæã«ç²¾åº¦ãè½ã¨ããã¨ã§ï¼float16ã32ã«ï¼ãã£ã¹ã¯ãµã¤ãºã®åæ¸ãã§ãã¾ãã
float64ãã16,32ã¸å¤æããã®ã¯astype(np.float32)ã¨ã¡ã½ãããå®è¡ããã°è¯ãã§ãã
å°ãç¹æ®ãªäºä¾ã§ããã0-1ã®å ´åã¯ã255ãä¹ç®ãããã¨ã§ãuint8ã§ç®¡çã§ãã¾ãã
ã¡ã¢ãªãéããã¦ããå ´åï¼Kernelãªã©ï¼ã«å©ç¨å¯è½ã§ãã
arr = np.random.rand(200000, 5000) arr = arr * 255 arr = arr.astype(np.uint8)
ä¸åº¦ã«å¤§éã®ãã¼ã¿ãèªã¾ãªã
ããããå
¨ã¦ã®ãã¼ã¿ãèªã¿è¾¼ã¿ãªã³ã¡ã¢ãªã§ç®¡çãããã¨ã¯é£ããå ´åãããã¾ãã
ãã¼ã¿ãå
¨ã¦è¼ãã管çãããã¨ãé¿ããã¹ãã§ãã
ä¾ãã°ãpandasã«ã¯ãchunkã¨å¼ã°ããã¡ã½ãããããããã®ã¡ã½ãããå©ç¨ãããã¨ã§é¨åçã«é çªã«èªãã¾ãã
ãã®ãããé¨åçã«èªã¿ã¤ã¤ãç¹å¾´éãªã©ãè¨ç®ãã¾ãããã
reader = pd.read_csv(fname, skiprows=[0, 1], chunksize=50) for r in reader: print (r)
ç¹å¾´éã®ã¿ä¿åãã
ä¸åº¦ã«å¤§éã®ãã¼ã¿ãèªã¾ãªãã«æ´¾çãã¾ãã
ç¹å¾´éã®ã¿ä¿åãã¦ããã¦çµåããæãããã¾ãã
ä¾ãã°ãã°ãã¼ã¿ã ã¨ããã°ã大åã®ãã°ãã¼ã¿ã¯åéãå¤ãã§ãã
é¨åçã«èªãã®ã«å ããç¹å¾´éã®è¨ç®ããã¦ããã°å
¨ã¦ã®ãã¼ã¿ãã¡ã¢ãªã§æã¤ãã¨ã¯ãªããªãã¾ãã
é¨åçã«èªã¿é²ããç¹å¾´éãè¨ç®ããä¿åãã¦ãããã¨ã§ãå¹çåã§ããã§ãããã
æå¾ã«
ã¡ã¢ãªã«è¼ããªããã¼ã¿ãæ±ãã®ã¯ãããããã¨ã§ãã
ãã®ããããã®ãããªæ¹æ³ã使ã£ã¦ãã¾ãæ±ããããã«ãªã£ã¦ããããã¨å¹¸ãã§ãã