I am basically trying to re-create numpy's reshape function. The user enters a list and a tuple. The tuple decides the dimension of the matrix.
My idea for finding the rows and columns is:
Take the length of the inputted list at the first or second element of the tuples index. So if the tuples first element is 3 then it should take the len of the arrays first 3 elements.
def reshape(array: list, rows_columns: tuple):
columns = [len(array(rows_columns[1]))]
rows = [len(array(rows_columns[0]))]
matrix = (rows, columns)
return matrix
reshape([1, 2, 3, 4], (2, 2))
But this is not possible I get TypeError: 'list' object is not callable. I just wanted to know if I thinking about it wrong.