transpose list python code example

Example 1: python transpose list

list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

numpy_array = np.array(list_of_lists)
transpose = numpy_array.T

transpose_list = transpose.tolist()

Example 2: how to transpose a 2d list in python

import numpy as np

def func(my_matrix):

	# Making np array of the list
	my_matrix = np.array(my_matrix)

	# Find the transpose to get image vector in column
	my_matrix = my_matrix.transpose()
    
    return my_matrix

Example 3: python list transpose

# Use numpy. T to transpose a list of lists, from kite.com

list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

numpy_array = np.array(list_of_lists)
transpose = numpy_array.T
transpose `numpy_array`

transpose_list = transpose.tolist()