I want to convert X,Y,Z numpy array to (X*Z)*Y numpy array.
Code(Slow):
def rearrange(data):
samples,channels,t_insts=data.shape
append_data=np.empty([0,channels])
for sample in range(0,samples):
for t_inst in range(0,t_insts):
channel_data=data[sample,:,t_inst]
append_data=np.vstack((append_data,channel_data))
return append_data.shape
I am looking for a better vectorized approach if possible
You can use np.transpose
to swap rows
with columns
and then reshape -
data.transpose(0,2,1).reshape(-1,data.shape[1])
Or use np.swapaxes
to do the swapping of rows and columns and then reshape -
data.swapaxes(1,2).reshape(-1,data.shape[1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With