FFT of 2D array along last axis

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

FFT of 2D array along last axis

Brad Buran
Given the following code: 

import numpy as np
x = np.random.random(size=2**14)
y = x.copy()
z = np.concatenate([x[np.newaxis], y[np.newaxis]], axis=0)
print(np.all(np.fft.fft(z, axis=-1)[0] == np.fft.fft(z[0])))

On Windows 7 using Anaconda with numpy 1.9.1 I get False (indicating that the FFT is not treating each row separately).  When I test on a Ubuntu box using numpy 1.9.1 I get True.  Is this expected behavior?  If I understand the documentation correctly, the FFT on each row should be independent (i.e. the result should not be influenced by the other rows).

Brad

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: FFT of 2D array along last axis

Stéfan van der Walt
Hi Brad

On 2014-11-07 00:51:02, Brad Buran <[hidden email]> wrote:
> On Windows 7 using Anaconda with numpy 1.9.1 I get False (indicating that
> the FFT is not treating each row separately).  When I test on a Ubuntu box
> using numpy 1.9.1 I get True.  Is this expected behavior?  If I understand
> the documentation correctly, the FFT on each row should be independent
> (i.e. the result should not be influenced by the other rows).

The results should be the same.  As an additional test, can you check:

np.testing.assert_array_almost_equal(np.fft.fft(z, axis=-1)[0], np.fft.fft(z[0]))

Thanks
Stéfan
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: FFT of 2D array along last axis

Brad Buran
So it seems that the error only occurs in np.fft.rfft (not np.fft.fft).  The following code:

import numpy as np
r = np.random.RandomState(seed=0)
z = r.randn(2**14).reshape((2, -1))
print(np.abs(np.fft.rfft(z)[0])[:5])
print(np.abs(np.fft.rfft(z[0]))[:5])


Prints out on a Windows 7 with Anaconda 64-bit:

[  94.22136166  149.3181169   145.77500588  177.39556729  172.05616019]
[ 128.55889109   77.35670747   69.63121452  109.06772033   66.22919485]


Prints out on a Ubuntu box:
[ 128.55889109   77.35670747   69.63121452  109.06772033   66.22919485]
[ 128.55889109   77.35670747   69.63121452  109.06772033   66.22919485]
On a Windows 7 with Python(x,y):

[ 128.55889109   77.35670747   69.63121452  109.06772033   66.22919485]
[ 128.55889109   77.35670747   69.63121452  109.06772033   66.22919485]
Brad


On Thu, Nov 6, 2014 at 3:28 PM, Stefan van der Walt <[hidden email]> wrote:
Hi Brad

On 2014-11-07 00:51:02, Brad Buran <[hidden email]> wrote:
> On Windows 7 using Anaconda with numpy 1.9.1 I get False (indicating that
> the FFT is not treating each row separately).  When I test on a Ubuntu box
> using numpy 1.9.1 I get True.  Is this expected behavior?  If I understand
> the documentation correctly, the FFT on each row should be independent
> (i.e. the result should not be influenced by the other rows).

The results should be the same.  As an additional test, can you check:

np.testing.assert_array_almost_equal(np.fft.fft(z, axis=-1)[0], np.fft.fft(z[0]))

Thanks
Stéfan
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion