[Numpy-discussion] simple way to denote unchanged dimension in reshape?

Chao YUE chaoyuejoy at gmail.com
Thu May 29 06:06:04 EDT 2014


Oh, I didn't think it out. thanks.

Chao


On Thu, May 29, 2014 at 11:59 AM, Dave Hirschfeld <dave.hirschfeld at gmail.com
> wrote:

> Chao YUE <chaoyuejoy <at> gmail.com> writes:
>
> >
> >
> >
> > Dear all,
> > I have a simple question. Is there a way to denote the unchanged
> dimension
> in the reshape function? like suppose I have an array named "arr" having
> three dims with the first dimension length as 48, I want to reshape the
> first dim into 12*4, but keeping all the other dimension length unchanged.
> >
> > like when we slice the array, we can use:  arr[10:40, ... ], "...'
> represents all remaining dimesions.
> >
> > however when doing reshape, we must use:
> >
> > arr.reshape(12,-1,arr.shape(1),arr.shape(2))
> >
> >
> > Is there something allowing more flexible reshape, like:
> >
> > arr.reshape(12,-1,...)?
> >
> > thanks a lot in advance,best,
> >
> > Chao
> >
>
> For the example given the below code works:
>
> In [1]: x = randn(48,5,4,3,2)
>
> In [2]: x.reshape(12,-1,*x.shape[1:]).shape
> Out[2]: (12L, 4L, 5L, 4L, 3L, 2L)
>
>
> HTH,
> Dave
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
please visit:
http://www.globalcarbonatlas.org/
***********************************************************************************
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140529/f45593fb/attachment.html>


More information about the NumPy-Discussion mailing list