Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Source code: Matrix Addition using Nested Loop

# Program to add two matrices using nested loop

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

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

result = [[0,0,0],
         [0,0,0],
         [0,0,0]]

# iterate through rows
for i in range(len(X)):
   # iterate through columns
   for j in range(len(X[0])):
       result[i][j] = X[i][j] + Y[i][j]

for r in result:
   print(r)
Comment

PREVIOUS NEXT
Code Example
Python :: Source Code: Check Armstrong number of n digits 
Python :: Dizideki en son elemani alma 
Python :: quicksort python3 
Python :: how to square in python 
Python :: online python pseudo code writer python 
Python :: upper method in python 
Python :: redirect user based on input with python cgi code 
Python :: webhook logger python 
Python :: print chr character in python f string 
Python :: repeat printing rows excel using python whenever i run the script 
Python :: integrate label into listbox tkinter 
Python :: what is a console in pythonanywhere 
Python :: how to make ui dialog pop in front pyqt 
Python :: RuntimeError: input must have 3 dimensions, got 4 site:stackoverflow.com 
Python :: matlab end of array 
Python :: tkinter lottery app 
Python :: pyqt message box set information text 
Python :: python matplotlib fullscreen zoom 
Python :: Reading from a file way01 
Python :: Python Modifying Global Variable From Inside the Function 
Python :: fancy index python 
Python :: Pandas index column title or name 
Python :: Indices may also be negative numbers, to start counting from the right:Indices may also be negative numbers, to start counting from the right: 
Python :: bs4 check element type 
Python :: Python RegEx Split – re.split() Syntax 
Python :: big python code 
Python :: set DJANGO_SETTINGS_MODULE=mysite.settings django-admin 
Python :: how to calculate the area and perimeter of a shape in python 
Python :: appropriate graph for data visualization 
Python :: Collecting package metadata (repodata.json): done Solving environment: failed ResolvePackageNotFound: - python==3.9.13 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =