Reputation: 119
This is the raw data
a=[[1,2,3,4,5,6],
[7,8,9,10,11,12]]
I want to convert it to the format like this:
b=[[1,2,3,7,8,9],
[4,5,6,10,11,12]]
array(List).swapaxes()
How to do it use reshape and swapaxes in python?
Thanks
Upvotes: 3
Views: 422
Reputation: 2739
try this:
import numpy as np
a = np.array([[1,2,3,4,5,6], [7,8,9,10,11,12]])
b = a.reshape((2, 2, 3)).swapaxes(0, 1).reshape(2, 6)
print(b)
check it out: https://coderpad.io/F7X7EKR4
Upvotes: 1