Home | | Problem Solving and Python Programming | Python Programs on matrix

# Python Programs on matrix

Problem Solving and Python Programming : Lists, Tuples, Dictionaries

Programs on matrix:

## Matrix addition

a=[[1,1],[1,1]]

b=[[2,2],[2,2]]

c=[[0,0],[0,0]]

for i in range(len(a)):

for j in range(len(b)):

c[i][j]=a[i][j]+b[i][j]

for i in c:

print(i)

[3, 3]

[3, 3]

## Matrix multiplication

a=[[1,1],[1,1]]

b=[[2,2],[2,2]]

c=[[0,0],[0,0]]

for i in range(len(a)):

for j in range(len(b)):

for k in range(len(b)):

c[i][j]=a[i][j]+a[i][k]*b[k][j]

for i in c:

print(i)

[3, 3]

[3, 3]

## Matrix transpose

a=[[1,3],[1,2]]

c=[[0,0],[0,0]]

for i in range(len(a)):

for j in range(len(a)):

c[i][j]=a[j][i]

for i in c:

print(i)

### Output

[1, 1]

[3, 2]

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Problem Solving and Python Programming : Lists, Tuples, Dictionaries : Python Programs on matrix |

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.