Find us on Facebook

Thursday, December 13, 2018

Python Program to Add Two arrays using function



Aim: Implement a program to add two matrix
Algorithm:
1.Start
2.Enter The first matrix
3.Enter the second matrix
3.call function Add(m1,m2)
4.print result
5.Stop

Function add(m1,m2)

1.Start
2.sum= append(m1[i][j]+m2[i][j])      
4.Stop
Program:
def add(m1,m2):        
            result=[]          
            for i in range(0,n):                  
                        sum1=[]                      
                        for j in range(0,m):                             
                                    result.append(m1[i][j]+m2[i][j])                     
                                    sum1.append(result)   
            return sum1


n=input("enter matrix limit")
m=input("enter matrix limit")
a=[]
print "first matrix"
for i in range(0,n):      
            b=[]    
            for i in range(0,m):
                        b.append(input())       
                        a.append(b)

print "second matrix"
c=[]
            for i in range(0,n):      
                        d=[]    
                        for i in range(0,m):                 
                                    d.append(input())       
                                    c.append(d)
print add(a,c)

            Output :
enter matrix limit:2
enter matrix limit:2
first matrix:2 3 4 5
second matrix:4 5 6 7
6 8
10 12

0 Comments:

Popular Posts

Text Widget

Search This Blog

Powered by Blogger.

Blogger Pages

Like Canvas?

Sponsor

Footer Widgetized Areas

About Canvas

About Canvas

Subscribe Us

About

Text Widget

Tags

Total Pageviews

print pdf

cal

Most Popular

    TUPLES
 LIST and SLICING
      ASCII VALUE
Copyright © KTU Btech Cse Python Lab Manuals | Powered by Blogger
Design by Saeed Salam | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates