From 0e26b7161f736e1bf404ba2019f0cbf6a700f39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=83=D0=B7=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=9F=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=BE?= <124675990+CrazyDuck192@users.noreply.github.com> Date: Tue, 21 Mar 2023 20:39:58 +0200 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D1=8F=20?= =?UTF-8?q?=D1=80=D0=BE=D0=B1=D0=BE=D1=82=D0=B0=20=E2=84=9614=20(=E2=84=96?= =?UTF-8?q?17.12)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 17.12.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 17.12.py diff --git a/17.12.py b/17.12.py new file mode 100644 index 0000000..6f20b33 --- /dev/null +++ b/17.12.py @@ -0,0 +1,38 @@ +def sparce_matrix(func): + + def _sparce_matrix(*args): + zeros = 0 + y = func(*args) + for row in y: + zeros += row.count(0) + + if zeros >= round(0.9*len(y[0])*len(y)): + return {(y.index(row)+1, row.index(i)+1): + i for row in y for i in row if i > 0} + return y + + return _sparce_matrix + + +def input_matrix(n, m): + matrix = [[0 for pos in range(m)] for row in range(n)] + for i in range(n): + for j in range(m): + matrix[i][j] = int(input(f'M({i+1}, {j+1})')) + + return matrix + +@sparce_matrix +def matrix_sum(a, b): + if len(a) != len(b) or len(a[0]) != len(b[0]): + raise Exception + + for i in range(len(a)): + for j in range(len(a[0])): + a[i][j] += b[i][j] + return a + +if __name__ == '__main__': + a = input_matrix(3, 2) + b = input_matrix(3, 2) + print(matrix_sum(a, b))