np.allclose(x_d_const, x - pp0(t)) # compare with constant detrend True >>> pp1 = np.polynomial.Polynomial.fit(t, x, deg=1) # fit degree 1 polynomial >>> np.allclose(x_d_linear, x - pp1(t)) # compare with linear detrend True Note that `~numpy.polynomial.polynomial.Polynomial` also allows fitting higher degree polynomials. Consult its documentation on how to extract the polynomial coefficients. )