python
matrix
5 years, 11 months ago
#Matrix Manipulations Without using any packages
#Define Matrix A,B,C
A=[[1,2,3],
[2,3,4],
[4,5,6]]
B=[[1,2,3],
[3,4,5],
[9,7,5]]
result=[[0,0,0],
[0,0,0],
[0,0,0]]
#Addition
for i in range(len(A)):
for j in range(len(B)):
result[i][j]=A[i][j]+B[i][j]
#Subtraction
for i in range(len(A)):
for j in range(len(B)):
result[i][j]=A[i][j]-B[i][j]
#Multiplication
for i in range(len(A)):
for j in range(len(B[0])):
for k in range(len(B)):
result[i][j]+=A[i][k]*B[k][j]
#Division by 2
for i in range(len(A)):
for j in range(len(A)):
result[i][j]=A[i][j]/2
#Transpose
for i in range(len(A[0])):
for j in range(len(A)):
result[i][j]=A[j][i]
result=0
#Add all the elements
for i in range(len(A)):
for j in range(len(A[0])):
result+=A[i][j
Change the result matrix dimension according to Matrix Dimensions properties
Product of (M*N) and (N*K) matrix is (M*K) Matrix.
0 Comments
Please Login to Comment Here