w3resource logo
Python Exercises

Python NumPy: Add, subtract, multiply, divide arguments element-wise

Python NumPy Math, Statistics, Trigonometry and Linear algebra: Exercise-1 with Solution

Write a Python program to add, subtract, multiply, divide arguments element-wise.
Sample elements: 4.0, 1.2

Sample Solution:-

Python Code:

import numpy as np
print("Add:")
print(np.add(1.0, 4.0))
print("Subtract:")
print(np.subtract(1.0, 4.0))
print("Multiply:")
print(np.multiply(1.0, 4.0))
print("Divide:")
print(np.divide(1.0, 4.0))

Sample Output:

Add:                                                                   
5.0                                                                    
Subtract:                                                              
-3.0                                                                   
Multiply:                                                              
4.0                                                                    
Divide:                                                                
0.25  

Python Code Editor:

Improve this sample solution and post your code through Disqus