MCPcopy
hub / github.com/numpy/numpy / polyadd

Function polyadd

numpy/lib/_polynomial_impl.py:798–863  ·  view source on GitHub ↗

Find the sum of two polynomials. .. 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:`transition guide </reference/routin

(a1, a2)

Source from the content-addressed store, hash-verified

796
797@array_function_dispatch(_binary_op_dispatcher)
798def polyadd(a1, a2):
799 """
800 Find the sum of two polynomials.
801
802 .. note::
803 This forms part of the old polynomial API. Since version 1.4, the
804 new polynomial API defined in `numpy.polynomial` is preferred.
805 A summary of the differences can be found in the
806 :doc:`transition guide </reference/routines.polynomials>`.
807
808 Returns the polynomial resulting from the sum of two input polynomials.
809 Each input must be either a poly1d object or a 1D sequence of polynomial
810 coefficients, from highest to lowest degree.
811
812 Parameters
813 ----------
814 a1, a2 : array_like or poly1d object
815 Input polynomials.
816
817 Returns
818 -------
819 out : ndarray or poly1d object
820 The sum of the inputs. If either input is a poly1d object, then the
821 output is also a poly1d object. Otherwise, it is a 1D array of
822 polynomial coefficients from highest to lowest degree.
823
824 See Also
825 --------
826 poly1d : A one-dimensional polynomial class.
827 poly, polyadd, polyder, polydiv, polyfit, polyint, polysub, polyval
828
829 Examples
830 --------
831 >>> import numpy as np
832 >>> np.polyadd([1, 2], [9, 5, 4])
833 array([9, 6, 6])
834
835 Using poly1d objects:
836
837 >>> p1 = np.poly1d([1, 2])
838 >>> p2 = np.poly1d([9, 5, 4])
839 >>> print(p1)
840 1 x + 2
841 >>> print(p2)
842 2
843 9 x + 5 x + 4
844 >>> print(np.polyadd(p1, p2))
845 2
846 9 x + 6 x + 6
847
848 """
849 truepoly = (isinstance(a1, poly1d) or isinstance(a2, poly1d))
850 a1 = atleast_1d(a1)
851 a2 = atleast_1d(a2)
852 diff = len(a2) - len(a1)
853 if diff == 0:
854 val = a1 + a2
855 elif diff > 0:

Callers 2

__add__Method · 0.70
__radd__Method · 0.70

Calls 2

atleast_1dFunction · 0.90
poly1dClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…