Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import stdin
- class Matrix:
- def __init__(self, arr):
- self.a = []
- for i in arr:
- self.a.append([])
- for j in i:
- self.a[-1].append(j)
- def __str__(self):
- res = ''
- for i in self.a:
- for j in i:
- res += str(j) + '\t'
- res = res[:-1] + '\n'
- return res[:-1]
- def size(self):
- return (len(self.a), len(self.a[0]))
- def __add__(self, m):
- res = []
- for i in range(len(self.a)):
- res.append([])
- for j in range(len(self.a[i])):
- res[-1].append(self.a[i][j]+m.a[i][j])
- return Matrix(res)
- def __mul__(self, v):
- res = []
- for i in range(len(self.a)):
- res.append([])
- for j in range(len(self.a[i])):
- res[-1].append(self.a[i][j]*v)
- return Matrix(res)
- __rmul__ = __mul__
- exec(stdin.read())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement