[Numpy-discussion] simple way to denote unchanged dimension in reshape?
dave.hirschfeld at gmail.com
Thu May 29 05:59:52 EDT 2014
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:
> Is there something allowing more flexible reshape, like:
> thanks a lot in advance,best,
For the example given the below code works:
In : x = randn(48,5,4,3,2)
In : x.reshape(12,-1,*x.shape[1:]).shape
Out: (12L, 4L, 5L, 4L, 3L, 2L)
More information about the NumPy-Discussion