Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class matrix:
- def __init__(self,numRows,numColumns):
- #@param:
- # numRow: int;
- # numColumns: int;
- self.rows = numRows
- self.cols = numColumns
- self.mat = {}
- def printMat(self):
- keys = list(self.mat.keys())
- p = makeMatrix(self.rows,self.cols)
- for i in range(0,len(keys)):
- m = int(keys[i][0])
- n = int(keys[i][1])
- p[m][n] = self.mat[keys[i]]
- for i in range(0,len(p)):
- print(p[i])
- def value(self,i):
- #@param:
- # i: tuple, (row_index,col_index);
- # return: float
- return(self.mat[i])
- def modif(self,i,v):
- #@param:
- # i: tuple, (row_index,col_index);
- # v: float;
- self.mat[i] = v
- def add(self,i,v):
- #@param:
- # i: tuple, (row_index,col_index);
- # v: float;
- self.mat[i] = v
- def matSum(self,otherMat):
- #@param:
- # otherMat: dict, class_matrix;
- # return: dict, class_matrix;
- if self.rows!=otherMat.rows or self.cols!=otherMat.cols:
- print("Matrices are not compatrible")
- return []
- else:
- key = list(otherMat.mat.keys())
- for i in key:
- self.mat[i] = self.mat.get(i,0) + otherMat.mat[i]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement