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
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.
4 Comments
It looks like you want either this from SciPy
scipy.fftpack.fft2
or the following from NumPy
numpy.fft.fft2
3 Comments
SciPy module correctly?