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@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion