Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reshape dataset using python like this

Tags:

reshape

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

like image 573
Bin Avatar asked Feb 28 '26 15:02

Bin


1 Answers

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

like image 58
Martin Gottweis Avatar answered Mar 04 '26 21:03

Martin Gottweis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!