Python Exercise Example44
# Python2.x Python Exercise Instance 44 - Python Add Two Matrices
[ Python 100 Examples](#)
Two 3x3 matrices, add the data in their corresponding positions, and return a new matrix:
X = [[12,7,3], [4 ,5,6], [7 ,8,9]] Y = [[5,8,1], [6,7,3], [4,5,9]]
Program Analysis: Create a new 3x3 matrix, use a for loop to iterate and extract the values at corresponding positions in the X and Y matrices, add them, and place them in the corresponding positions of the new matrix.
Program Source Code:
## Source Code:
#!/usr/bin/python# -*- coding: UTF-8 -*-X = [[12,7,3], [4 ,5,
YouTip