Python Programming - Arithmetic Operations On Array

You can learn about NumPy in Python Programs with Outputs helped you to understand the language better.

Read Also: Python Program to Find Leaders in an Array/List

Python Programming – Arithmetic Operations On Array

NumPy is not only about efficient storing of data but also makes it extremely easy to perform the arithmetic operations on multi-dimensional arrays directly. In the following example, the arithmetic operations are performed on the two multi-dimensional arrays.

Example
Demo of arithmetic operations.

import numpy as np
a = np.array([[10,20,30], [10,15,4]])
b = np.array![[2,4,8] , [5, 19, 29]])
print(“Sum of array a and b\n”,a+b)
print(“Product of array a and b\n”,a*b)
print(“Division of array a and b\n”,a/b)RUN
>>>
Sum of array a and b
[[12 24 38]
[15 34 33]]
Product of array a and b
[[ 20 80 240]
[ 50 285 116]]
Division of array a and b
[ [5. 5 . 3.75 ]
[2. 0.78947368 0.13793103]]
>>>

Let’s Try

import numpy as np
x = np. array ( [ [12,16,15] , [10,15,4] ] )
y = np.array( [ [2,4,5], [5, 3, 2]])
print(“Sum of array\n”,x+y)
print(“Product of array \n”,x*y)
print(“Division of array\n”,x/y)

Leave a Reply

Your email address will not be published. Required fields are marked *