def transpose(matrix):
    rows = len(matrix)
    cols = len(matrix[0]) if rows else 0
    output = [[0] * rows for _ in range(cols)]
    for r in range(rows):
        for c in range(cols):
            output[c][r] = matrix[r][c]
    return output
