I am new to Python and have been struggling to create a matrix from a sequence of integers(i.e. *range(2,17)) without using numpy.
def create_matrix(*NumList, rows, cols):
Fmat = []
for row in range(rows):
Imat = []
for col in range(cols):
Imat.append(None)
Fmat.append(Imat)
return Fmat
print (create_matrix(*range(2, 17), rows=3, cols=5))
How can I replace 'None' with NumList so the matrix will take the integers from the range instead, as I encounter an error when appending more than 1 argument using append(). Moreover, how can I ensure that the shape of matrix can match with the numbers (i.e. print error message if the matrix cannot be possibly generated).
Thanks for your help!