[Python] How to do 100000 times 2d fft in a faster way using python?

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have a 3d numpy array with a shape of (100000, 256, 256), and I'd like to do FFT on every stack of the 2d array, which means 100000 times of FFT.

    I have tested the speed of single and the stacked data with minimum code below.

    import numpy as np
    a = np.random.random((256, 256))
    b = np.random.random((10, 256, 256))

    %timeit np.fft.fft2(a)

    %timeit np.fft.fftn(b, axes=(1, 2,))


    Which gives the following:

    872 µs ± 19.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

    6.46 ms ± 227 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

    100000 times of fft will take more than one minite.

    Is there any faster way to do multiple fft or ifft at the same time?

    Update: After a bit search, I found cupy, which seems can help.

    Continue reading...

Compartilhe esta Página