为什么运行此脚本会冻结我的电脑?

时间:2017-01-08 08:57:43

标签: python scipy freeze fftpack

我使用SciPy在Python中编写了一个脚本,对信号执行短时傅立叶变换。当我用一千个时间点的信号运行它时,运行正常。当我用一百万个时间点的信号运行它时,它冻结了我的计算机(计算机没有响应,如果正在播放音频,则计算机输出跳过和循环的嗡嗡声);这种情况一直发生在我尝试过的三次。我编写的脚本需要花费数小时,但我从未遇到过真正冻结计算机的脚本。知道为什么吗?该脚本发布在下面:

import scipy as sp
from scipy import fftpack

def STFT(signal, seconds_per_sample, window_seconds, min_Hz):
    window_samples = int(window_seconds/seconds_per_sample) + 1
    signal_samples = len(signal)
    if signal_samples <= window_samples:
        length = max(signal_samples, int(1/(seconds_per_sample*min_Hz)) + 1)
        return sp.array([0]), fftpack.fftshift(fftpack.fftfreq(length, seconds_per_sample)), fftpack.fftshift(fftpack.fft(signal, n = length))
    else:
        length = max(window_samples, int(1/(seconds_per_sample*min_Hz)) + 1)
        frequency = fftpack.fftshift(fftpack.fftfreq(length, seconds_per_sample))
        time = []
        FTs = []
        for i in range(signal_samples - window_samples):
            time.append(seconds_per_sample*i)
            FTs.append(fftpack.fftshift(fftpack.fft(signal[i:i + window_samples], n = length)))
        return sp.array(time), frequency, sp.array(FTs)

1 个答案:

答案 0 :(得分:-1)

当你在太多的点上运行时,脚本中的

消耗了太多的RAM,请参阅Why does a simple python script crash my system

程序运行的过程在进程内存中存储用于计算的数组和变量,这是ram

您可以通过强制程序使用硬盘内存来解决此问题。

有关变通办法(shelve,...),请参阅以下链接

memory usage, how to free memory

Python large variable RAM usage

I need to free up RAM by storing a Python dictionary on the hard drive, not in RAM. Is it possible?