Skip to content

Instantly share code, notes, and snippets.

@hamzaavvan
Created October 6, 2019 09:47
Show Gist options
  • Save hamzaavvan/d23894f56bb7d15258da41b351fe566f to your computer and use it in GitHub Desktop.
Save hamzaavvan/d23894f56bb7d15258da41b351fe566f to your computer and use it in GitHub Desktop.
Python - Creating Dynamic Matrices
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