I wrote a transpose matrix function however, when I try to run it the values inside the output becomes the same in the end. Attached there is a picture of the output. My code is also commented.
def transpose(any_matrix):
_row = len(any_matrix)
_col = len(any_matrix[0])
temp_matrix = []
#multiplies [0] by the number of rows (old) to create new row
temp_row = [0]*_row
#creates matrix with number of columns as rows
for x in range(_col):
temp_matrix += [temp_row]
for r in range(len(any_matrix)):
for c in range(len(any_matrix[0])):
value = any_matrix[r][c]
temp_matrix[c][r] = value
return temp_matrix
a = [[4, 5, 6], [7,8,9]]
print(transpose(a))
#input [[4,5,6]
# [7,8,9]]
#correct answer [ [4,7],
# [5,8],
# [6,9] ]
I prefer not to use other libraries such as numpy etc. output