Python -> Typeerror: Unsupported Operand Type(s) For ^
I am struggling with Python code. I want to do this equation. This my code: fs= 5000 T=np.linspace(0,2.2,fs) n=np.arange(fs*2.2) u=[] for x in T: if x < 0.2: u.appen
Solution 1:
The power operator is **
, ^
is bitwise XOR.
Solution 2:
Beyond the mistake ^/**
, the good way is to use np.piecewise
which is intended for that for a quick vectored result:
fs= 5000
x=np.linspace(0,2.2,fs)
n=3
functions=[
lambda x : x * np.sin(34*np.pi*n/fs),
lambda x : 1/x * np.log10(x+1),
lambda x : (x**2 + 1) * np.sin(12*np.pi*n/fs),
lambda x : np.sin(20*np.pi*n/fs + x/3)]
conditions=[x < 0.2,(x >= 0.2) & (x < 0.8), (x >= 0.8) & (x < 1.4), x >= 1.4]
res=np.piecewise(x,conditions,functions)
plt.plot(x,res)
just loop on n
for all the values.
Post a Comment for "Python -> Typeerror: Unsupported Operand Type(s) For ^"