Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109620 > unrolled thread

reshape and keep x,y,z ordering

Started byHeli <hemla21@gmail.com>
First post2016-06-07 04:25 -0700
Last post2016-06-07 06:37 -0700
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  reshape and keep  x,y,z ordering Heli <hemla21@gmail.com> - 2016-06-07 04:25 -0700
    Re: reshape and keep x,y,z ordering Joel Goldstick <joel.goldstick@gmail.com> - 2016-06-07 08:48 -0400
    Re: reshape and keep x,y,z ordering Michael Selik <michael.selik@gmail.com> - 2016-06-07 13:16 +0000
      Re: reshape and keep x,y,z ordering Heli <hemla21@gmail.com> - 2016-06-07 06:37 -0700

#109620 — reshape and keep x,y,z ordering

FromHeli <hemla21@gmail.com>
Date2016-06-07 04:25 -0700
Subjectreshape and keep x,y,z ordering
Message-ID<5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com>
Hello, 

I have a question regarding reshaping numpy array. 

I either have a 1D array that I need to reshape to a 3D array or a 3D array to reshape to a 1d numpy array. 

In both of these cases it is assumed that data follows x,y,z ordering.

and I use the following to reshape the numpy array. 


new_1d_array=np.reshape(3d.transpose(),(3d_nx*3d_ny*3d_nz,)) 


new_3d_array=np.reshape(1d,((3d_x,3d_y,3d_z)).transpose())

My question is if there is anyway that reshape would keep x,y,z ordering that would not require transpose? and if there is a better more efficient way to do this?

Thanks alot, 

[toc] | [next] | [standalone]


#109625 — Re: reshape and keep x,y,z ordering

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2016-06-07 08:48 -0400
SubjectRe: reshape and keep x,y,z ordering
Message-ID<mailman.58.1465303695.2306.python-list@python.org>
In reply to#109620
On Tue, Jun 7, 2016 at 7:25 AM, Heli <hemla21@gmail.com> wrote:
> Hello,
>
> I have a question regarding reshaping numpy array.
>
> I either have a 1D array that I need to reshape to a 3D array or a 3D array to reshape to a 1d numpy array.
>
> In both of these cases it is assumed that data follows x,y,z ordering.
>
> and I use the following to reshape the numpy array.
>
>
> new_1d_array=np.reshape(3d.transpose(),(3d_nx*3d_ny*3d_nz,))
>
>
> new_3d_array=np.reshape(1d,((3d_x,3d_y,3d_z)).transpose())
>
> My question is if there is anyway that reshape would keep x,y,z ordering that would not require transpose? and if there is a better more efficient way to do this?
>
> Thanks alot,
> --
> https://mail.python.org/mailman/listinfo/python-list

Sorry, I can't help, others may be able to help you here.  But there
is also a numpy specific mailing list you might try

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays

[toc] | [prev] | [next] | [standalone]


#109626 — Re: reshape and keep x,y,z ordering

FromMichael Selik <michael.selik@gmail.com>
Date2016-06-07 13:16 +0000
SubjectRe: reshape and keep x,y,z ordering
Message-ID<mailman.59.1465305415.2306.python-list@python.org>
In reply to#109620
On Tue, Jun 7, 2016 at 7:31 AM Heli <hemla21@gmail.com> wrote:

> Hello,
> I have a question regarding reshaping numpy array.
>
> I either have a 1D array that I need to reshape to a 3D array or a 3D
> array to reshape to a 1d numpy array.
>
> In both of these cases it is assumed that data follows x,y,z ordering.
> and I use the following to reshape the numpy array.
>
> new_1d_array=np.reshape(3d.transpose(),(3d_nx*3d_ny*3d_nz,))
>
> new_3d_array=np.reshape(1d,((3d_x,3d_y,3d_z)).transpose())
>
> My question is if there is anyway that reshape would keep x,y,z ordering
> that would not require transpose? and if there is a better more efficient
> way to do this?


    >>> a = np.arange(9).reshape(3,3)
    >>> a
    array([[0, 1, 2],
           [3, 4, 5],
           [6, 7, 8]])
    >>> a.flatten()
    array([0, 1, 2, 3, 4, 5, 6, 7, 8])
    >>> a.flatten('F')
    array([0, 3, 6, 1, 4, 7, 2, 5, 8])

Does this work for you?
The flatten method normally goes row by row, but you can specify FORTRAN
style column by column flattening.

[toc] | [prev] | [next] | [standalone]


#109627 — Re: reshape and keep x,y,z ordering

FromHeli <hemla21@gmail.com>
Date2016-06-07 06:37 -0700
SubjectRe: reshape and keep x,y,z ordering
Message-ID<66c545f1-c031-467d-ba55-e530b1d8891d@googlegroups.com>
In reply to#109626
Thanks Michael, 

This did the trick. array.flatten('F') works exactly as I need. 

Thanks a lot, 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web