def invertibleroots(ma): import numpy.polynomial as poly pr = poly.polyroots(ma) insideroots = np.abs(pr) < 1 if insideroots.any(): pr[np.abs(pr) < 1] = 1. / pr[np.abs(pr) < 1] pnew = poly.Polynomial.fromroots(pr) mainv = pn.coef / pnew.coef[0] wasinvertible = False else: mainv = ma wasinvertible = True return mainv, wasinvertible
def invertibleroots(ma): import numpy.polynomial as poly pr = poly.polyroots(ma) insideroots = np.abs(pr)<1 if insideroots.any(): pr[np.abs(pr)<1] = 1./pr[np.abs(pr)<1] pnew = poly.Polynomial.fromroots(pr) mainv = pn.coef/pnew.coef[0] wasinvertible = False else: mainv = ma wasinvertible = True return mainv, wasinvertible