Hello,
I'm having a hard time understanding something:
returns the error:
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 :
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 !
I'm having a hard time understanding something:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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))) |
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 :
1 2 3 4 5 |
n = np.arange( 0 , 10 ) def f(x): return 2 * x plot(n, f(n)) |
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 !