如何避免Jupyter Notebook中的内存错误

时间:2019-02-13 08:55:24

标签: python-3.x jupyter-notebook ubuntu-16.04

我正在Jupyter笔记本中运行该程序。

    import numpy as np
    import scipy as sp
    import matplotlib.pyplot as plt

    f=sp.fromfile(open("RSM_07_02_2019_lpf_v1"),dtype=sp.float32)
    samp_250000=f[1:350001]
    samp_250000_reshp=np.reshape(samp_250000,[7,50000])
    unit_250000=np.ones([50000,50000])
    cmul=(1/35000)*np.matmul(unit_250000,np.transpose(samp_250000_reshp))
    diff=np.transpose(samp_250000_reshp)-cmul
    cov=np.matmul(np.transpose(diff),diff)
    print(cov)

运行时出现错误

    MemoryError                               Traceback (most recent call last)
    <ipython-input-5-ab4aadfd66e1> in <module>()
          6 samp_250000=f[1:350001]
          7 samp_250000_reshp=np.reshape(samp_250000,[7,50000])
    ----> 8 unit_250000=np.ones([50000,50000])
          9 cmul=(1/35000)*np.matmul(unit_250000,np.transpose(samp_250000_reshp))
         10 diff=np.transpose(samp_250000_reshp)-cmul

    ~/anaconda3/lib/python3.7/site-packages/numpy/core/numeric.py in ones(shape, dtype, order)
        201 
        202     """
    --> 203     a = empty(shape, dtype, order)
        204     multiarray.copyto(a, 1, casting='unsafe')
        205     return a

    MemoryError: 

可能是什么原因?

1 个答案:

答案 0 :(得分:0)

我在Kaggle forum上遇到的提示

还有另一个提示,请确保您使用的是ipython / jupyter笔记本, 确保当前笔记本是唯一正在运行的笔记本。 同时关闭所有其他应用程序。

为我工作,我有几个笔记本在后台运行,将它们关闭以清理足够的空间。

enter image description here