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

Function polyadd

numpy/lib/polynomial.py:789–853  ·  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

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

Callers 2

__add__Method · 0.70
__radd__Method · 0.70

Calls 3

atleast_1dFunction · 0.90
absFunction · 0.85
poly1dClass · 0.85

Tested by

no test coverage detected