[Numpy-discussion] numpy.fft.irfftn fails apparently unexpectedly

Torgil Svensson torgil.svensson@gmail....
Mon Feb 6 18:04:47 CST 2012


irfftn is an optimization for real input and does not take complex
input. You have to use numpy.fft.ifftn instead:

>>>> import numpy
>>>> a_shape = (63, 4, 98)
>>>> a = numpy.complex128(numpy.random.rand(*a_shape)+\
> ...     1j*numpy.random.rand(*a_shape))
>>>>
>>>> axes = [0, 2]
>>>>
>>>> numpy.fft.ifftn(a, axes=axes)

Or do you mean if the error message is expected?

Best Regards,
//Torgil


On Mon, Feb 6, 2012 at 7:32 PM, Henry Gomersall <heng@cantab.net> wrote:
> Is the following behaviour expected:
>
>>>> import numpy
>>>> a_shape = (63, 4, 98)
>>>> a = numpy.complex128(numpy.random.rand(*a_shape)+\
> ...     1j*numpy.random.rand(*a_shape))
>>>>
>>>> axes = [0, 2]
>>>>
>>>> numpy.fft.irfftn(a, axes=axes)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "/usr/lib/pymodules/python2.7/numpy/fft/fftpack.py", line 1080,
> in irfftn
>    s, axes = _cook_nd_args(a, s, axes, invreal=1)
>  File "/usr/lib/pymodules/python2.7/numpy/fft/fftpack.py", line 515, in
> _cook_nd_args
>    s[axes[-1]] = (s[axes[-1]] - 1) * 2
> IndexError: list index out of range
>
> The implication from the docs is that axes can be arbitrary. The
> following *does* work fine:
>
>>>> import numpy
>>>> a = numpy.float64(numpy.random.rand(*a_shape))
>>>> axes = [0, 2]
>>>> numpy.fft.rfftn(a, axes=axes)
>
>
> Thanks,
>
> Henry
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list