So I'm assuming here that fp(x) or f(x) are functions that don't return anything.
Take a look at this,
def fp(x):
print(x)
print(fp(10))
You might think that the output of this would be 10 but you get this,
10
None
Take a look at this function,
def fp():
pass
print(fp())
Output:
None
Functions by default return a None type. So in your case when you are doing abs(fp(x)) the problem seems to be that you are doing abs() on None that's why you get the error.
Look at this,
def fp():
pass
abs(fp())
Output:
TypeError: bad operand type for abs(): 'NoneType' python error
So add a return statement to the function and you can see the error will be gone
def fp(x):
return x
some_value = abs(fp(-10.5))
print(some_value)
Output:
10.5
Now the error is gone.
Answer from void on Stack OverflowAPI Integration - TypeError: bad operand type for abs(): 'NoneType'
Python absolute value
Erreur : bad operand type for abs(): sur creation de Sales Order
'Bad operand type for abs', how do i solve this
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])
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'