How to multiply two 2D RFFT arrays (FFTPACK) to be compatible with NumPy’s FFT?

Correct functions: import numpy as np from scipy import fftpack as scipy_fftpack from scipy import fft as scipy # FFTPACK RFFT 2D def fftpack_rfft2d(matrix): fftRows = scipy_fftpack.fft(matrix, axis=1) fftCols = scipy_fftpack.fft(fftRows, axis=0) return fftCols # FFTPACK IRFFT 2D def fftpack_irfft2d(matrix): ifftRows = scipy_fftpack.ifft(matrix, axis=1) ifftCols = scipy_fftpack.ifft(ifftRows, axis=0) return ifftCols.real You calculated the 2D FFT … Read more

Why using an array as an index changes the shape of a multidimensional ndarray?

As @hpaulj mentioned in the comments, this behaviour is because of mixing basic slicing and advanced indexing: a = np.arange(120).reshape(4,5,3,2) b = a[:,[1,2,3,4,0],:,0] In the above code snippet, what happens is the following: when we do basic slicing along last dimension, it triggers a __getitem__ call. So, that dimension is gone. (i.e. no singleton dimension) … Read more