2

I am new to python and getting this error, please help me out correct it.

AttributeError: 'module' object has no attribute 'fft2'

Program

import numpy, scipy , pylab , wave , scipy.io.wavfile as wav 
xs = numpy.arange (1,100,.01)
rate , sample = wav.read("pianotest.wav")
fft2=scipy.fft2(sample) # algo applied
bp=fft2[:]  
for i in range(len(bp)): 
if i>=10:bp[i]=0  
ibp=scipy.ifft2(bp) # inverse algo
print"to check dimension"
print("sampling rate = {} Hz, length = {} samples, channels = {}".format(rate,   *sample.shape))
print(sample)

3 Answers 3

4

Instead of scipy.fft2 and scipy.ifft2, do scipy.fftpack.fft2, or numpy.fft.fft2.

Also, add import scipy.fftpack2 to the top of your code, and then everything should work fine.

Look here for more information on scipy.fftpack.fft2 or here for information on numpy.fft.fft2.

Here is your edited code:

import numpy, scipy , pylab , wave, scipy.fftpack, scipy.io.wavfile as wav 
xs = numpy.arange (1,100,.01)
rate , sample = wav.read("pianotest.wav")
fft2=scipy.fftpack.fft2(sample) # algo applied
bp=fft2[:]  
for i in range(len(bp)): 
if i>=10:bp[i]=0  
ibp=scipy.fftpack.ifft2(bp) # inverse algo
print"to check dimension"
print("sampling rate = {} Hz, length = {} samples, channels = {}".format(rate,   *sample.shape))
print(sample)

If it still isn't working, check to see if your scipy version is 0.14.0 by typing python -c "import scipy; print scipy.__version__" into your command prompt. If it doesn't show 0.14.0 or above, then upgrade your version of scipy.

Sign up to request clarification or add additional context in comments.

4 Comments

still shows the same error as "AttributeError: 'module' object has no attribute 'fftpack'"
Thank you, just need to add another line "from scipy.fftpack import fft2, ifft2 " at the top and it works fine
@user3699203 if this answer helped you, feel free to accept it by clicking the green check mark next to my answer. Full disclosure: it gives you +2 reputation :)
@aj8uppal next time, link to this post: How does accepting an answer work
1

It looks like you want either this from SciPy

scipy.fftpack.fft2

or the following from NumPy

numpy.fft.fft2

3 Comments

AttributeError: 'module' object has no attribute 'fftpack'
Are you sure you installed the SciPy module correctly?
Thanks, just need to add another line "from scipy.fftpack import fft2, ifft2 " at the top and it works fine
1

According to the docs here and here it should be either numpy.fft.fft2 or scipy.fftpack.fft2, not scipy.fft2.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.