分割NumPy数组时出现内存错误

2024-04-25 09:31:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我在计算信号的脉冲响应。代码如下:

def impulse_response(self):
    # Inverse filter:
    T = self.recorded_data.shape[0] / self.samplerate
    t = np.arange(0, T*self.samplerate - 1) / self.samplerate
    R = np.log(20/20000)
    k = np.exp(t*R/T).astype(np.float32)
    f = self.recorded_data[::-1] / k  # Gives an MemoryError
    # Impulse response:
    return sig.fftconvolve(self.recorded_data, f, mode="same")

计算滤波器f时的除法给出内存错误。 self.recorded_data是15秒的正弦扫描,采样频率为44100Hz,其282240字节大。k的大小为2822396字节(两个数组都是32位浮点型)。我认为把这些数组除掉不会是个大问题。分割的方式有问题吗?也许有更有效的方法吗?还是应该使用其他数据类型?在

我使用https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.ndarray.nbytes.html找到的数组大小

在我的transfer_function()函数中分割NumPY数组时也会遇到相同的错误,所以我想这是相同的问题。在

我从https://dsp.stackexchange.com/questions/41696/calculating-the-inverse-filter-for-the-exponential-sine-sweep-method得到代码

顺便说一下,我的电脑有8GB的内存。在

谢谢你的回答!在


Tags: the内存代码httpsselfnumpydata字节
1条回答
网友
1楼 · 发布于 2024-04-25 09:31:32

我把-1t = np.arange(0, T*self.samplerate - 1) / self.samplerate中删除了-1。看着我复制的代码,我不知道它是怎么来的!k不应比1个样品短自记数据所以我得到了一个错误:ValueError: operands could not be broadcast together with shapes (661500,) (661499,)。我必须更加小心地复查我正在处理的数据的维度。。。在

相关问题 更多 >