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

Function polydiv

numpy/lib/polynomial.py:978–1047  ·  view source on GitHub ↗

Returns the quotient and remainder of polynomial division. .. note:: This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in `numpy.polynomial` is preferred. A summary of the differences can be found in the :doc:`transitio

(u, v)

Source from the content-addressed store, hash-verified

976
977@array_function_dispatch(_polydiv_dispatcher)
978def polydiv(u, v):
979 """
980 Returns the quotient and remainder of polynomial division.
981
982 .. note::
983 This forms part of the old polynomial API. Since version 1.4, the
984 new polynomial API defined in `numpy.polynomial` is preferred.
985 A summary of the differences can be found in the
986 :doc:`transition guide </reference/routines.polynomials>`.
987
988 The input arrays are the coefficients (including any coefficients
989 equal to zero) of the "numerator" (dividend) and "denominator"
990 (divisor) polynomials, respectively.
991
992 Parameters
993 ----------
994 u : array_like or poly1d
995 Dividend polynomial&#x27;s coefficients.
996
997 v : array_like or poly1d
998 Divisor polynomial&#x27;s coefficients.
999
1000 Returns
1001 -------
1002 q : ndarray
1003 Coefficients, including those equal to zero, of the quotient.
1004 r : ndarray
1005 Coefficients, including those equal to zero, of the remainder.
1006
1007 See Also
1008 --------
1009 poly, polyadd, polyder, polydiv, polyfit, polyint, polymul, polysub
1010 polyval
1011
1012 Notes
1013 -----
1014 Both `u` and `v` must be 0-d or 1-d (ndim = 0 or 1), but `u.ndim` need
1015 not equal `v.ndim`. In other words, all four possible combinations -
1016 ``u.ndim = v.ndim = 0``, ``u.ndim = v.ndim = 1``,
1017 ``u.ndim = 1, v.ndim = 0``, and ``u.ndim = 0, v.ndim = 1`` - work.
1018
1019 Examples
1020 --------
1021 .. math:: \\frac{3x^2 + 5x + 2}{2x + 1} = 1.5x + 1.75, remainder 0.25
1022
1023 >>> x = np.array([3.0, 5.0, 2.0])
1024 >>> y = np.array([2.0, 1.0])
1025 >>> np.polydiv(x, y)
1026 (array([1.5 , 1.75]), array([0.25]))
1027
1028 """
1029 truepoly = (isinstance(u, poly1d) or isinstance(v, poly1d))
1030 u = atleast_1d(u) + 0.0
1031 v = atleast_1d(v) + 0.0
1032 # w has the common type
1033 w = u[0] + v[0]
1034 m = len(u) - 1
1035 n = len(v) - 1

Callers 2

__div__Method · 0.70
__rdiv__Method · 0.70

Calls 4

atleast_1dFunction · 0.90
poly1dClass · 0.85
astypeMethod · 0.80
maxFunction · 0.50

Tested by

no test coverage detected