def transpose(lst):
return list(map(list, zip(*lst)))
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()
# 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()
arr_t = np.array(l_2d).T
print(arr_t)
print(type(arr_t))
# [[0 3]
# [1 4]
# [2 5]]
# <class 'numpy.ndarray'>
l_2d_t = np.array(l_2d).T.tolist()
print(l_2d_t)
print(type(l_2d_t))
# [[0, 3], [1, 4], [2, 5]]
# <class 'list'>
x = [[0,1],[2,3]]
np.transpose(x).tolist()
array([[0, 2],
[1, 3]])
[list(i) for i in zip(*l)]