Hello,
I'm having a hard time understanding something:
I thought the "n" sent to filtrage() by "plot(n, divisionEuclide(u1-filtrage(n,u1)))" was a integer of the array n, not the array itself, since :
So why is the whole array sent to the function filtrage in the first example ? And how do I change that ?
I hope you can help me, thank you !
I'm having a hard time understanding something:
from pylab import * import numpy as np import numpy.fft as npft import scipy.io.wavfile as wavfile import math fs_u1 , u1 = wavfile.read("u1.wav") #u1 is a numpy array of complex values n= np.arange(0,u1.size) def module(z): # returns the module of the complex z a = z.real b = z.imag return math.sqrt(a**2+b**2) def filtrage(M, y) : # should take an int M and a numpy array y, return a numpy array ychap = np.fft.fft(y) N = ychap.size mask = np.ones(N) coord = np.arange(M+1,N-M,1) mask[coord]=0 yfiltchap = mask*ychap yfilt = np.fft.ifft(yfiltchap) yfilt = yfilt.real return yfilt def divisionEuclide(x): # should return the sum of the modules of all the complex value of the numpy array sent to it sum = 0 for i in(n): sum+= module(x[i])**2 return sum plot(n, divisionEuclide(u1-filtrage(n,u1)))returns the error:
Error:File "...", line 29, in filtrage
coord = np.arange(M+1,N-M,1)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I thought the "n" sent to filtrage() by "plot(n, divisionEuclide(u1-filtrage(n,u1)))" was a integer of the array n, not the array itself, since :
n = np.arange(0,10) def f(x): return 2*x plot(n, f(n))works just fine.
So why is the whole array sent to the function filtrage in the first example ? And how do I change that ?
I hope you can help me, thank you !