Transpose of Matrix

Hint

Transpose is to set m[i][j] = m[j][i].

# Python implementation
matrix = [
  [ 1, 2, -1, -4, -20 ],
  [ -8, -3, 4, 2, 1 ],
  [ 3, 8, 10, 1, 3 ],
  [ -4, -1, 1, 7, -6 ]
]
h = len(matrix)
w = len(matrix[0])
output = [['' for _ in range(h)] for _ in range(w)]

for i in range(w):
  for j in range(h):
    output[i][j] = matrix[j][i]

print(output)
// Javascript implementation
const matrix = [
  [ 1, 2, -1, -4, -20 ],
  [ -8, -3, 4, 2, 1 ],
  [ 3, 8, 10, 1, 3 ],
  [ -4, -1, 1, 7, -6 ]
];
const h = matrix.length;
const w = matrix[0].length;
const output = JSON.parse(JSON.stringify(Array(w).fill(Array(h).fill(""))));

for (let i = 0; i < w; i++) {
  for (let j = 0; j < h; j++) {
    output[i][j] = matrix[j][i];
  }
}

console.log(output);