I wrote the following function for Matrix transpose :
def transpose(mat):
row = len(mat)
column = len(mat[0])
transposeMatrix = [[0] * row] * column # Initialize Transpose Array
for i in range(row):
for j in range(column):
transposeMatrix[j][i] = mat[i][j]
print(f'output[{j}][{i}] = input[{i}][{j}] = {transposeMatrix[j][i]}')
return transposeMatrix
print(transpose([[1,2,3],[4,5,6]]))
The debugging print statement inside function seems to be working the way I wanted to, but the original output is always incorrect
Input:
[[1,2,3],[4,5,6]]
Expected Output:
[[1, 4], [2, 5], [3, 6]]
Original Output:
[[3, 6], [3, 6], [3, 6]]