-1

I want to change the x and y axis of a matrix. For example I want to store the first element of each nested array in the first line, the second of each nested array on the second line etc... For example:

list = [[1,2,3,4,5,6]
        [7,8,9,10,11,12]
        [13,14,15,16,17,18]
        [19,20,21,22,23,24]]

I want to change into this:

new list = [[1,7,13,19]
            [2,8,14,20]
            [3,9,15,21]
            [4,10,16,22]
            [5,11,17,23]
            [6,12,18,24]]

Note: This isnt a rotation

1 Answers1

3
import numpy as np

data = [[1,2,3,4,5,6],
        [7,8,9,10,11,12],
        [13,14,15,16,17,18],
        [19,20,21,22,23,24]]

# convert the list of lists to an array
data = np.array(data)

# transpose the array
data_t = data.T

# print(data_t)
array([[ 1,  7, 13, 19],
       [ 2,  8, 14, 20],
       [ 3,  9, 15, 21],
       [ 4, 10, 16, 22],
       [ 5, 11, 17, 23],
       [ 6, 12, 18, 24]])
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158