MCPcopy Index your code
hub / github.com/numpy/numpy / polymul

Function polymul

numpy/lib/_polynomial_impl.py:924–984  ·  view source on GitHub ↗

Find the product 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/ro

(a1, a2)

Source from the content-addressed store, hash-verified

922
923@array_function_dispatch(_binary_op_dispatcher)
924def polymul(a1, a2):
925 """
926 Find the product of two polynomials.
927
928 .. note::
929 This forms part of the old polynomial API. Since version 1.4, the
930 new polynomial API defined in `numpy.polynomial` is preferred.
931 A summary of the differences can be found in the
932 :doc:`transition guide </reference/routines.polynomials>`.
933
934 Finds the polynomial resulting from the multiplication of the two input
935 polynomials. Each input must be either a poly1d object or a 1D sequence
936 of polynomial coefficients, from highest to lowest degree.
937
938 Parameters
939 ----------
940 a1, a2 : array_like or poly1d object
941 Input polynomials.
942
943 Returns
944 -------
945 out : ndarray or poly1d object
946 The polynomial resulting from the multiplication of the inputs. If
947 either inputs is a poly1d object, then the output is also a poly1d
948 object. Otherwise, it is a 1D array of polynomial coefficients from
949 highest to lowest degree.
950
951 See Also
952 --------
953 poly1d : A one-dimensional polynomial class.
954 poly, polyadd, polyder, polydiv, polyfit, polyint, polysub, polyval
955 convolve : Array convolution. Same output as polymul, but has parameter
956 for overlap mode.
957
958 Examples
959 --------
960 >>> import numpy as np
961 >>> np.polymul([1, 2, 3], [9, 5, 1])
962 array([ 9, 23, 38, 17, 3])
963
964 Using poly1d objects:
965
966 >>> p1 = np.poly1d([1, 2, 3])
967 >>> p2 = np.poly1d([9, 5, 1])
968 >>> print(p1)
969 2
970 1 x + 2 x + 3
971 >>> print(p2)
972 2
973 9 x + 5 x + 1
974 >>> print(np.polymul(p1, p2))
975 4 3 2
976 9 x + 23 x + 38 x + 17 x + 3
977
978 """
979 truepoly = (isinstance(a1, poly1d) or isinstance(a2, poly1d))
980 a1, a2 = poly1d(a1), poly1d(a2)
981 val = NX.convolve(a1, a2)

Callers 3

__mul__Method · 0.70
__rmul__Method · 0.70
__pow__Method · 0.70

Calls 1

poly1dClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…