-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.py
53 lines (48 loc) · 1.05 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def initilising_matrix(dim):
c=[]
for i in range(dim):
c.append([])
for i in range(dim):
for j in range(dim):
c[i].append(0)
return c
# dot product of matrix
def dot_product(u,v):
ans=0
dim=len(u)
for i in range (dim):
ans=ans+u[i]*v[i]
return ans
# find the row of a matrix
def row_matrix(m,i):
l=[]
dim=len(m)
for j in range(dim):
l.append(m[i][j])
return l
def column_matrix(m,j):
pass
M=[[1,2,3],[4,5,6],[6,7,8]]
print(row_matrix(M,0))
def column_matrix(m,j):
l=[]
dim=len(m)
for i in range(dim):
l.append(m[i][j])
return l
print(column_matrix(M,2))
def matrix_mul(M,X):
dim=len(M)
c= initilising_matrix(dim)
for i in range(dim):
for j in range(dim):
c[i][j]=c[i][j]+(dot_product(row_matrix(M,i),column_matrix(x,j)))
return c
x=[[1,2,3],[4,5,6],[7,8,9]]
print(matrix_mul(M,x))
import numpy
X=numpy.mat(M)
y=numpy.mat(x)
b=(X*y)
print(b)
import pandas as pd