Skip to content

Arutyunyan Mikael #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
from random import randint
from multiprocessing import Pool

def write(a):
with open('result.txt', 'a') as f:
f.write(str(a) + " ")

def element(index, A, B):
i, j = index
res = 0
# get a middle dimension
N = len(A[0]) or len(B)
for k in range(N):
res += A[i][k] * B[k][j]
return res
def multiplication(x, y):
rez = sum(i*k for i, k in zip(x, y))
return rez

matrix1 = [[randint(0, 15) for i in range(3)] for i in range(3)]
print(f'Первая матрица = {matrix1}')

matrix1 = [[1, 2], [3, 4]]
matrix2 = [[2, 0], [1, 2]]
matrix2 = [[randint(0, 10) for i in range(3)] for i in range(3)]
print(f'Вторая матрица = {matrix2}')

print(element((1, 0), matrix1, matrix2))
with Pool(4) as pool:
matric = pool.starmap(multiplication, [(i, k) for i in matrix1 for k in zip(*matrix2)])
print(matric, 'result.txt')
write(matric)
Empty file added result.txt
Empty file.