I see you've already imported numpy because you're using np.linspace in the code. You are probably confusing numpy's abs, which will happily work on lists and arrays, with __builtin__.abs, which only works for scalars.
Change this:
abs(wf[0:100])
To this:
np.abs(wf[0:100])
Answer from wim on Stack OverflowI see you've already imported numpy because you're using np.linspace in the code. You are probably confusing numpy's abs, which will happily work on lists and arrays, with __builtin__.abs, which only works for scalars.
Change this:
abs(wf[0:100])
To this:
np.abs(wf[0:100])
I gather that you want abs applied to each member of the list slice along with some other computation, since you use slice notation. That's easy with a list comprehension.
plot(sf, [2.0/numSamples * abs(element) for element in wf[0:100]]);
print("Enter a integer:") var1=input() print(abs(var1))
this is the error I get when I run it
TypeError: bad operand type for abs(): 'str'