Created
October 6, 2019 09:47
-
-
Save hamzaavvan/d23894f56bb7d15258da41b351fe566f to your computer and use it in GitHub Desktop.
Python - Creating Dynamic Matrices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def createMatrix(): | |
_matrix = [] | |
ms=int(input("Enter no. of matrices to create: ")) | |
for i in range(ms): | |
print("\nMatrix %i"%(i+1)) | |
r=int(input("\tEnter no. of rows: ")) | |
c=int(input("\tEnter no. of columns: ")) | |
m=[] | |
b=[] | |
for i in range(r): | |
for j in range(c): | |
v= int(input("\tEnter value for row "+str(i)+" column "+str(j)+": ")) | |
b.append(v) | |
m.append(b) | |
b=[] | |
_matrix.append(m) | |
return _matrix | |
matrix = createMatrix() | |
# Sample 2 Matrices assigning to m1 & m2 | |
m1 = matrix[0] | |
m2 = matrix[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment