IanHacker IanHacker - 27 days ago 21
Python Question

TypeError: bad operand type for abs(): 'list'

The following simple code returns: TypeError: bad operand type for abs(): 'list'

from scipy.signal import residue

def x_filter():
p = [complex(-2505.707527665261,3165.104073896715),complex(-2505.707527665261,-3165.104073896715),complex(-3449.516723926777,1032.914743287806),complex(-3449.516723926777,-1032.914743287806)]
r = [complex(-1981.17378001573,2672.79673635191),complex(-1981.17378001573,-2672.79673635191),complex(1981.17378001573,-10000.37025226017),complex(1981.17378001573,10000.37025226017)]
k = []

[b,a]=residue(r,p,k)

filtered = x_filter()


I replaced p and r with:

p = [-2505.707527665261+3165.104073896715j,-2505.707527665261-3165.104073896715j,-3449.516723926777+1032.914743287806j,-3449.516723926777-1032.914743287806j]
r = [-1981.17378001573+2672.79673635191j,-1981.17378001573-2672.79673635191j,1981.17378001573-10000.37025226017j,1981.17378001573+10000.37025226017j]


..., but makes no difference.

Am I doing something wrong?
Is there any workaround?

I referred to bad operand type for abs(): 'list', but I cannot apply that solution because the __builtin__.abs() function is used in scipy.signal.residue (not in my code).

Answer

Looking at the docs docs, it seems that you mistook inputs for outputs. residue takes a and b and returns r, p and k.

Third parameter (tol) should be a number but you are passing a list.


You might be using wrong method. Take a look at scipy.signal.invres, that should be what you are looking for.