Python Program to add two matrices using zip()

preview_player
Показать описание
# Program to add two matrices
# using zip()

X = [[1,2,3],
[4 ,5,6],
[7 ,8,9]]

Y = [[9,8,7],
[6,5,4],
[3,2,1]]

result = [map(sum, zip(*t)) for t in zip(X, Y)]

print(result)
Output
[[10, 10, 10], [10, 10, 10], [10, 10, 10]]
Рекомендации по теме