NumPy: Add, subtract, multiply and divide polynomials
NumPy Mathematics: Exercise-18 with Solution
Write a NumPy program to add one polynomial to another, subtract one polynomial from another, multiply one polynomial by another and divide one polynomial by another.
from numpy.polynomial import polynomial as P x = (10,20,30) y = (30,40,50) print("Add one polynomial to another:") print(P.polyadd(x,y)) print("Subtract one polynomial from another:") print(P.polysub(x,y)) print("Multiply one polynomial by another:") print(P.polymul(x,y)) print("Divide one polynomial by another:") print(P.polydiv(x,y))
Add one polynomial to another: [ 40. 60. 80.] Subtract one polynomial from another: [-20. -20. -20.] Multiply one polynomial by another: [ 300. 1000. 2200. 2200. 1500.] Divide one polynomial by another: (array([ 0.6]), array([-8., -4.]))
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Getting rid of unwanted characters:
You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.
str="+++Welcome python+++" str.strip() print(str)
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework