【问题标题】:How to interpret Pythone memory usage with guppy?如何用 guppy 解释 Python 内存使用情况?
【发布时间】:2016-08-01 17:31:05
【问题描述】:

我正在使用代码进行地球物理时间序列的频谱估计。

import matplotlib.pyplot as plt
plt.style.use("ggplot")
import numpy as np
from mtspec import mtspec
from mtspec.util import _load_mtdata

from guppy import hpy
h = hpy()
print h.heap()

data = np.loadtxt('500.dat')

spec,freq,jackknife,f_statistics,degrees_of_f = mtspec(data=data, delta= 40.0, time_bandwidth=4 ,number_of_tapers=7, nfft= 512, statistics=True)

我知道了:

milenko@milenko-HP-Compaq-6830s:~$ python mt4.py 
Partition of a set of 214843 objects. Total size = 35303944 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0  15461   7  8538896  24   8538896  24 unicode
     1  77241  36  7769768  22  16308664  46 str
     2  43700  20  3870600  11  20179264  57 tuple
     3    582   0  1443984   4  21623248  61 dict of PyQt4.QtCore.pyqtWrapperType
     4    352   0  1395712   4  23018960  65 dict of module
     5  10118   5  1295104   4  24314064  69 types.CodeType
     6    858   0  1265136   4  25579200  72 dict (no owner)
     7   9893   5  1187160   3  26766360  76 function
     8   1123   1  1112392   3  27878752  79 dict of type
     9   1123   1  1012552   3  28891304  82 type
<900 more rows. Type e.g. '_.more' to view.>

如果我采用 1000 点的时间序列(以前的情况是 500),我得到的结果是一样的:

milenko@milenko-HP-Compaq-6830s:~$ python mt5.py
Partition of a set of 214843 objects. Total size = 35303944 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0  15461   7  8538896  24   8538896  24 unicode
     1  77241  36  7769768  22  16308664  46 str
     2  43700  20  3870600  11  20179264  57 tuple
     3    582   0  1443984   4  21623248  61 dict of PyQt4.QtCore.pyqtWrapperType
     4    352   0  1395712   4  23018960  65 dict of module
     5  10118   5  1295104   4  24314064  69 types.CodeType
     6    858   0  1265136   4  25579200  72 dict (no owner)
     7   9893   5  1187160   3  26766360  76 function
     8   1123   1  1112392   3  27878752  79 dict of type
     9   1123   1  1012552   3  28891304  82 type
<900 more rows. Type e.g. '_.more' to view.>

所以这意味着时间序列加倍(我可以看到)没有任何变化。如何解释这个?guppy 对我来说是正确的选择吗?

【问题讨论】:

    标签: python memory-management guppy


    【解决方案1】:

    确实是老问题,但不妨把这个扔在那里......

    您正在加载文件之前进行内存分析——如果您在调用np.loadtxt(...) 之后移动print h.heap(),我想它会合并您想要的数据

    【讨论】:

      猜你喜欢
      • 2012-06-02
      • 1970-01-01
      • 2021-07-20
      • 2018-10-11
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      相关资源
      最近更新 更多