MCPcopy Create free account
hub / github.com/numpy/numpy / chebpow

Function chebpow

numpy/polynomial/chebyshev.py:817–872  ·  view source on GitHub ↗

Raise a Chebyshev series to a power. Returns the Chebyshev series `c` raised to the power `pow`. The argument `c` is a sequence of coefficients ordered from low to high. i.e., [1,2,3] is the series ``T_0 + 2*T_1 + 3*T_2.`` Parameters ---------- c : array_like 1-D a

(c, pow, maxpower=16)

Source from the content-addressed store, hash-verified

815
816
817def chebpow(c, pow, maxpower=16):
818 """Raise a Chebyshev series to a power.
819
820 Returns the Chebyshev series `c` raised to the power `pow`. The
821 argument `c` is a sequence of coefficients ordered from low to high.
822 i.e., [1,2,3] is the series ``T_0 + 2*T_1 + 3*T_2.``
823
824 Parameters
825 ----------
826 c : array_like
827 1-D array of Chebyshev series coefficients ordered from low to
828 high.
829 pow : integer
830 Power to which the series will be raised
831 maxpower : integer, optional
832 Maximum power allowed. This is mainly to limit growth of the series
833 to unmanageable size. Default is 16
834
835 Returns
836 -------
837 coef : ndarray
838 Chebyshev series of power.
839
840 See Also
841 --------
842 chebadd, chebsub, chebmulx, chebmul, chebdiv
843
844 Examples
845 --------
846 >>> from numpy.polynomial import chebyshev as C
847 >>> C.chebpow([1, 2, 3, 4], 2)
848 array([15.5, 22. , 16. , ..., 12.5, 12. , 8. ])
849
850 """
851 # note: this is more efficient than `pu._pow(chebmul, c1, c2)`, as it
852 # avoids converting between z and c series repeatedly
853
854 # c is a trimmed copy
855 [c] = pu.as_series([c])
856 power = int(pow)
857 if power != pow or power < 0:
858 raise ValueError("Power must be a non-negative integer.")
859 elif maxpower is not None and power > maxpower:
860 raise ValueError("Power is too large")
861 elif power == 0:
862 return np.array([1], dtype=c.dtype)
863 elif power == 1:
864 return c
865 else:
866 # This can be made more efficient by using powers of two
867 # in the usual way.
868 zs = _cseries_to_zseries(c)
869 prd = zs
870 for i in range(2, power + 1):
871 prd = np.convolve(prd, zs)
872 return _zseries_to_cseries(prd)
873
874

Callers

nothing calls this directly

Calls 2

_cseries_to_zseriesFunction · 0.85
_zseries_to_cseriesFunction · 0.85

Tested by

no test coverage detected