Reshape 2D array into 3D

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Reshape 2D array into 3D

paul.carrico

Dear All

I'm looking in a way to reshape a 2D matrix into a 3D one ; in my example I want to move the columns from the 4th to the 8th in the 2nd plane  (3rd dimension i guess)

a =  np.random.rand(5,8); print(a)

I tried

a = p.reshape(d, (2,5,4), ) but it is not what I'm expecting


Nota : it looks like the following task (while I want to split it in 2 levels and not in 4), but I've not understood at all

https://stackoverflow.com/questions/31686989/numpy-reshape-and-partition-2d-array-to-3d


Thanks for your support


Paul





_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reshape 2D array into 3D

Matthieu Brucher-2
Hi, 

This works, but reshape doesn't move data around. What happens is that the data is flattened and then reshaped. If your 5 is not supposed to move, you should create a 2,5,4 array and then copy the two slices by hand, or use transpose (make it 5,4,2 and then transpose to 2,5,4=.

Matthieu 

Le 10 juil. 2017 11:40 AM, <[hidden email]> a écrit :

Dear All

I'm looking in a way to reshape a 2D matrix into a 3D one ; in my example I want to move the columns from the 4th to the 8th in the 2nd plane  (3rd dimension i guess)

a =  np.random.rand(5,8); print(a)

I tried

a = p.reshape(d, (2,5,4), ) but it is not what I'm expecting


Nota : it looks like the following task (while I want to split it in 2 levels and not in 4), but I've not understood at all

https://stackoverflow.com/questions/31686989/numpy-reshape-and-partition-2d-array-to-3d


Thanks for your support


Paul





_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Loading...