Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. from sys import stdin
  2. from copy import deepcopy
  3.  
  4.  
  5. class Matrix(object):
  6.  
  7. def __init__(self, x):
  8. self.mat = deepcopy(x)
  9.  
  10. def __str__(self):
  11. sR = ""
  12. a = 0
  13. for mat in self.mat:
  14. if a != 0:
  15. sR += "\n"
  16. new_s = "\t".join(str(i) for i in mat)
  17. sR += new_s
  18. a += 1
  19. return sR
  20.  
  21. def size(self):
  22. return len(self.mat), len(self.mat[0])
  23.  
  24. def __add__(self, other):
  25. return Matrix(list(map(
  26. lambda x, y: list(map(lambda z, w: z + w, x, y)),
  27. self.mat, other.matrix)))
  28.  
  29. def __mul__(self, other):
  30. return Matrix([[i * other for i in j] for j in self.mat])
  31.  
  32. __rmul__ = __mul__
  33.  
  34.  
  35. exec(stdin.read())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement