[NumPy-Tickets] [NumPy] #1420: irfft2 handles axes argument improperly
NumPy Trac
numpy-tickets@scipy....
Thu Mar 4 09:44:45 CST 2010
#1420: irfft2 handles axes argument improperly
----------------------------+-----------------------------------------------
Reporter: sivaldimarsson | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: numpy.fft | Version:
Keywords: irfft2 |
----------------------------+-----------------------------------------------
The following output of an interactive session shows how numpy.fft.irfft
handles axes argument badly. The workaround is to use irfftn with a shape
argument as shown.
siv@siv-desktop:~/Documents$ ipython
Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
Type "copyright", "credits" or "license" for more information.
IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import numpy as np
In [3]: import numpy.fft as npfft
In [4]: a = np.zeros((256,256))
In [5]: a.shape
Out[5]: (256, 256)
In [9]: a[0:10,0:100] = 1
In [11]: ahat = npfft.rfft2(a,axes=(1,0))
In [12]: ahat.shape
Out[12]: (129, 256)
In [14]: ahatinvhat = npfft.irfft2(ahat,axes=(1,0))
In [15]: ahatinvhat.shape
Out[15]: (129, 510)
In [16]: ahatinvhat - a
ValueError Traceback (most recent call last)
/home/siv/Documents/<ipython console> in <module>()
ValueError: shape mismatch: objects cannot be broadcast to a single shape
In [22]: chat = npfft.rfftn(a,s=a.shape,axes=(1,0))
In [23]: chat.shape
Out[23]: (129, 256)
In [24]: np.max(np.abs(ahat-chat))
Out[24]: 0.0
In [25]: chatinvhat = npfft.irfftn(chat,s=a.shape,axes=(1,0))
In [26]: chatinvhat.shape
Out[26]: (256, 256)
In [27]: np.max(np.abs(a-chatinvhat))
Out[27]: 6.6613381477509392e-16
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1420>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list