On Mon, Jun 3, 2013 at 9:44 AM, Chao YUE <[email protected]> wrote: > Dear all, > > I have an array with 4 dim: > > In [24]: dd.shape > Out[24]: (12, 13, 120, 170) > > I would like to collapse the last two dim for applying np.sum(axis=-1) > > In [25]: dd.reshape(12,13,-1).shape > Out[25]: (12, 13, 20400) > > is there a more general way to do this? something like > In [21]: dd.reshape(*dd.shape[0:2],-1).shape > ------------------------------------------------------------ > File "<ipython console>", line 1 > SyntaxError: only named arguments may follow *expression (<ipython console>, > line 1)
dd.reshape(dd.shape[:-2] + (-1,)) -- Robert Kern _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
