Rearranging Numpy Array
import numpy as np a = np.array([[1,2], [3,4], [5,6], [7,8], [9,10], [11,12]]) print np.shape(a) The expected a
Solution 1:
You could use some reshaping and swapping of axes, like so -
L = 3# Cutting lengthout = a.reshape(-1,L,a.shape[1]).swapaxes(0,1).reshape(L,-1)
Or use np.transpose
to swap the axes, like so -
out = a.reshape(-1,L,a.shape[1]).transpose(1,0,2).reshape(L,-1)
Post a Comment for "Rearranging Numpy Array"