I checked the solution in Creating a Matrix in Python without numpy but this only address square matrixes. That is 3x3 or 4x4.
For example, I tried the answer in those questions with the following lines and it gives list index out of range error.
random_list = random.sample(range(10,99), 10)
print(len(random_list))
mat = createMatrix(5,2,random_list)
print (mat)
My question is given a list with numbers, how to put it into a matrix.
e.g.
column = input("No of Column: ")
rows = input("No of Rows: ")
randomDataList = random.sample(range(10,99), int(column)* int(rows))
createMatrix(int(column), int(rows), randomDataList)
Aucun commentaire:
Enregistrer un commentaire