Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to add two matrix using function in python

def generate_matrix(noOfRows, x):
    print("Enter the values of matrix -", (x+1))
    matrix = []
    for i in range(noOfRows):
        row = []
        for j in range(noOfRows):
            row.append(int(input()))
        matrix.append(row)
    return matrix


noOfRows = int((input("How many rows = ")))
m1 = generate_matrix(noOfRows, 0)
m2 = generate_matrix(noOfRows, 1)

sum = []

for x in range(noOfRows):
    row = []
    for y in range(noOfRows):
        row.append(m1[x][y] + m2[x][y])
    sum.append(row)
print(sum)

Comment

PREVIOUS NEXT
Code Example
Python :: get tail of dataframe pandas 
Python :: split data train python 
Python :: print class python 
Python :: append path to sys jupyter notebook 
Python :: creating base models django 
Python :: python install jedi 
Python :: python iterate through string in reverse 
Python :: update queryset in django 
Python :: delete one pymongo 
Python :: pandas drop column in dataframe 
Python :: python write binary 
Python :: handle errors in flask 
Python :: python operators 
Python :: pil crop image 
Python :: fstring 
Python :: changing plot background color in python 
Python :: button onclick message box in python tkinter 
Python :: plt.savefig specify dpi 
Python :: How to install pandas-profiling 
Python :: cmd check if python is installed 
Python :: python code to generate fibonacci series 
Python :: how to add an item to a dictionary in python 
Python :: how to create model in tensorflow 
Python :: string formatting in python 
Python :: text to audio in python 
Python :: saving model in pytorch 
Python :: python timestamp to yyyy-mm-dd 
Python :: remove nans and infs python 
Python :: django dockerfile multistage 
Python :: how to create a python script to automate software installation? 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =