БГ
Size: a a a
БГ
БГ
AT
AT
БГ
БГ
a = [[...], [...], ...]
b = [[...], [...], ...]
c=[]
for x, row in enumerate(a):
c.append(list())
for y, item in enumerate(row):
c[x].append(item + b[x][y])
AT
AT
mat0 = [[0]*3]*3
mat1 = [[x+i for i in range(3)] for x in range(1, 10, 3)]
mat2 = [[a + b for a, b in zip(x, y)] for x, y in zip(mat0, mat1)]
def matsum(*matrices):
return [list(map(sum, zip(*x))) for x in zip(*matrices)]
print(mat0, mat1, mat2, sep='\n')
print(matsum(mat0, mat1))
print(matsum(mat1, mat2))
AT
AT
БГ
mat0 = [[0]*3]*3
mat1 = [[x+i for i in range(3)] for x in range(1, 10, 3)]
mat2 = [[a + b for a, b in zip(x, y)] for x, y in zip(mat0, mat1)]
def matsum(*matrices):
return [list(map(sum, zip(*x))) for x in zip(*matrices)]
print(mat0, mat1, mat2, sep='\n')
print(matsum(mat0, mat1))
print(matsum(mat1, mat2))
AT
БГ
AT
БГ
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[[2, 4, 6], [8, 10, 12], [14, 16, 18]]
DY
БГ
DY
АР