Questions

How do you find the Sum of a Matrix in Python?

The sum of the matrices is obtained using the for loop, using nested list comprehension, and by using the zip().

Source Code for finding the sum of the matrices using the zip():

The zip() function takes an iterator for each matrix element, maps them, and then adds them using the sum() function. It returns the result and saves it in the mapping form.

                    

X = [[1,2,3],

    [4 ,0,6],

    [7 ,8,9]]

Y = [[9,4, 7],

    [6,5,2],

    [3,2,6]]

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

  print(result)

Related Questions

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.