Advertisement
Taigar2000

F

Nov 14th, 2020
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from sys import stdin
  2.  
  3.  
  4. class Matrix:
  5.     def __init__(self, arr):
  6.         self.a = []
  7.         for i in arr:
  8.             self.a.append([])
  9.             for j in i:
  10.                 self.a[-1].append(j)
  11.  
  12.     def __str__(self):
  13.         res = ''
  14.         for i in self.a:
  15.             for j in i:
  16.                 res += str(j) + '\t'
  17.             res = res[:-1] + '\n'
  18.         return res[:-1]
  19.  
  20.     def size(self):
  21.         return (len(self.a), len(self.a[0]))
  22.  
  23.     def __add__(self, m):
  24.         res = []
  25.         for i in range(len(self.a)):
  26.             res.append([])
  27.             for j in range(len(self.a[i])):
  28.                 res[-1].append(self.a[i][j]+m.a[i][j])
  29.         return Matrix(res)
  30.  
  31.     def __mul__(self, v):
  32.         res = []
  33.         for i in range(len(self.a)):
  34.             res.append([])
  35.             for j in range(len(self.a[i])):
  36.                 res[-1].append(self.a[i][j]*v)
  37.         return Matrix(res)
  38.  
  39.     __rmul__ = __mul__
  40.  
  41. exec(stdin.read())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement