-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.py
31 lines (22 loc) · 883 Bytes
/
Matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#to perform operations on matrix using numpy
from numpy import * #importing numpy module
arr=array ([ [1,2,3],[4,5,6] ]) #creating array from numpy
print(arr)
m=matrix(arr) # matrix function is inbuilt in numpy #one way of creating a matrix
print(m) #ouput looks similar but we can perform certain operations
# when input is taken from the user (second way of creating a matrix)
m=matrix('3,2;4,1')
print(m)
m=matrix('3,2;4,1;1,3;7,7') # rows are separated from other rows by using a semicolon in between
print(m)
m1=matrix('1,2,3;4,5,6;7,8,9')
print(m1)
print(diagonal(m1)) #inbuilt function used to print the diagonal values of a matrix
print(m1.min()) #prints min value in matrix
print(m1.max()) #prints max value in matrix
m2=matrix('9,8,7;6,5,4;3,2,1')
m3=m1+m2 #matrix additon
print(m3)
m4=m1*m2 #matrix multplication
print(m4)
#Code by Steavo Babu