Skip to content

Commit e53f04f

Browse files
Merge pull request souravjain540#169 from sagarmishra1103/main
Added MatrixOperation.py file to the directory.
2 parents b6f6ee5 + 6e7d3c4 commit e53f04f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

MatrixOperation.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#Prgram Code Created by Shivsagar Mishra
2+
#This is a program to perform basic matrix operarations such as 1. Addition 2.Substraction 3.Multiplication 4.Transpose
3+
4+
5+
import numpy as np
6+
7+
# Initialize matrix
8+
a = np.array([[1,2,1], [6,5,4], [9,5,8]])
9+
b = np.array([[3,2,1], [8,6,4], [4,0,0]])
10+
11+
while True:
12+
print("List of operations:\n1.Display\n2.Addition\n3.Substraction\n4.Multiplication\n5.Transpose")
13+
counter=int(input("Enter the your Choice:"))
14+
15+
if counter == 1:
16+
#printing 1st matrix
17+
print("First Matrix:")
18+
print (a,"\n")
19+
# printing 2nd Matrix
20+
print("Second Matrix:")
21+
print(b,"\n")
22+
23+
elif counter == 2:
24+
print ("The addition of matrices is : ")
25+
print(a.__add__(b),"\n")
26+
27+
elif counter == 3:
28+
print ("The Substraction of matrices is : ")
29+
print ("Substraction is:")
30+
print(a.__sub__(b),"\n")
31+
32+
elif counter == 4:
33+
print ("The multiplication of matrices is : ")
34+
print(a.__mul__(b),"\n")
35+
36+
elif counter == 5:
37+
print ("The Transposition of First matrix is: ")
38+
print(np.transpose(a),"\n")
39+
print("The Transposition of Second Matrix is:")
40+
print(np.transpose(b),"\n")
41+
else:
42+
print("Invalid Option!")
43+
44+
cont=int(input("Do you want to continue?: 1.Yes\t 2.No\t Enter your choice:"))
45+
if cont==1:
46+
continue
47+
else:
48+
break
49+

0 commit comments

Comments
 (0)