# numpy
import numpy as np
import random
# Creating a random 2d array object
M1 = np.random.randint(10, size=(2,2))
M2= np.random.randint(10, size=(2,2))
print("Generated array object")
print(M1)
print(M2)
# Array operations
print("Array operations")
print("Sum")
print(np.add(M1,M2))
print("Difference")
print(np.subtract(M1,M2))
print("Product")
print(np.dot(M1,M2))
print("Division")
np.set_printoptions(precision=2)
print(np.divide(M1,M2))
"""
Sample output
>python 8_5_numpy2.py
Generated array object
[[8 3]
[0 7]]
[[8 5]
[5 6]]
Array operations
Sum
[[16 8]
[ 5 13]]
Difference
[[ 0 -2]
[-5 1]]
Product
[[79 58]
[35 42]]
Division
[[1. 0.6 ]
[0. 1.17]]
"""
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu