在 Python (Matplotlib) 中重用模块引用
我想我可能在这里误解了一些东西......但是这里是。
我在循环内使用 matplotlib 中的 psd 方法,我没有让它绘制任何内容,我只想得到数值结果,所以:
import pylab as pyl
...
psdResults = pyl.psd(inputData, NFFT=512, Fs=sampleRate, window=blackman)
但是每次我运行它所在的函数时,它都会循环 36 次。
我得到当我随着时间的推移运行程序时,会出现缓慢的内存泄漏,因此使用“heapy”来监视这一点,每次运行该函数时,它都会向这 3 个堆添加 36:
dict matplotlib.line.Line26
dict matplotlib.transforms.CompositeAffine2D
dict matplotlib.path.Path
我只能得出结论,每次使用 psd 方法时只是将其添加到某处的某个字典中,而我想有效地擦除内存 - 即重置 pylab 每个循环,以便它不存储任何内容。
我可能会误解 heapy,但很明显 pylab 只是增长每个循环,即使我只想使用它的 psd 方法,我不希望它将结果保存在任何地方!
干杯
I think I may have misunderstood something here... But here goes.
I'm using the psd method in matplotlib inside a loop, I'm not making it plot anything, I just want the numerical result, so:
import pylab as pyl
...
psdResults = pyl.psd(inputData, NFFT=512, Fs=sampleRate, window=blackman)
But that's being looped 36 times every time I run the function it's in.
I'm getting a slow memory leak when I run my program over time, so used 'heapy' to monitor this, and every time I run the function, it adds 36 to these 3 heaps:
dict matplotlib.line.Line26
dict matplotlib.transforms.CompositeAffine2D
dict matplotlib.path.Path
I can only conclude that each time I use the psd method it merely adds it to some dictionary somewhere, whereas I want to effectively wipe the memory - i.e. reset pylab each loop so it doesn't store anything.
I could be misinterpreting heapy but it seems pretty clear that pylab is just growing each loop even though I only want to use it's psd method, I don't want it saving the results anywhere itself !
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
这会改善情况吗?
Try this:
Does that improve the situation?