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