<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import copy <EOL> import numpy as np <EOL> from scipy . signal import lti <EOL> def cancelPZ ( arg1 , tol = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( arg1 , lti ) : <EOL> arg1 = lti ( * arg1 ) <EOL> z = copy . copy ( arg1 . zeros ) <EOL> p = copy . copy ( arg1 . poles ) <EOL> k = arg1 . gain <EOL> for i in range ( max ( z . shape ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> d = z [ i ] - p <EOL> cancel = np . nonzero ( np . abs ( d ) < tol ) [ <NUM_LIT:0> ] <EOL> if cancel . size : <EOL> p = np . delete ( p , cancel [ <NUM_LIT:0> ] ) <EOL> z = np . delete ( z , i ) <EOL> return z , p , k </s>
