numpy.polymul(a1, a2)
The numpy.polymul
function finds the product (multiplication) of two polynomials a1
and a2
. As an input, use either poly1d objects or one-dimensional sequences of polynomial coefficients. If you use the latter, arange this polynomial sequence naturally from highest to lowest degree.
Arguments | Type | Description |
---|---|---|
a1, a2 | array_like or poly1d object | The input polynomials to be multiplied |
Return Value | ndarray or poly1d object | The polynomial resulting from the multiplication of the inputs. If either inputs is a poly1d object, then the output is also a poly1d object. Otherwise, it is a 1D array of polynomial coefficients from highest to lowest degree. |
Examples
import numpy as np print(np.polymul([1, 2, 3], [2, 3, 4])) # [ 2 7 16 17 12]
You can also use poly1d objects:
import numpy as np p1 = np.poly1d([1, 2, 3]) p2 = np.poly1d([2, 3, 4]) print(p1) print(p2) print(np.polymul(p1, p2)) ''' 2 1 x + 2 x + 3 2 2 x + 3 x + 4 4 3 2 2 x + 7 x + 16 x + 17 x + 12 '''
As you see the output looks much like a real polynomial if you use poly1d objects.
Any master coder has a “hands-on” mentality with a bias towards action. Try it yourself—play with the function in the following interactive code shell:
Exercise: Change the parameters of your polynomials. How does the output change? Guess and check!
Master NumPy—and become a data science pro:

Related Video

Emily Rosemary Collins is a tech enthusiast with a strong background in computer science, always staying up-to-date with the latest trends and innovations. Apart from her love for technology, Emily enjoys exploring the great outdoors, participating in local community events, and dedicating her free time to painting and photography. Her interests and passion for personal growth make her an engaging conversationalist and a reliable source of knowledge in the ever-evolving world of technology.