[Numpy-discussion] reshaping array question

Robert Kern robert.kern at gmail.com
Tue Nov 17 14:05:09 EST 2015


On Nov 17, 2015 6:53 PM, "Sebastian Berg" <sebastian at sipsolutions.net>
wrote:
>
> On Di, 2015-11-17 at 13:49 -0500, Neal Becker wrote:
> > Robert Kern wrote:
> >
> > > On Tue, Nov 17, 2015 at 3:48 PM, Neal Becker <ndbecker2 at gmail.com>
wrote:
> > >>
> > >> I have an array of shape
> > >> (7, 24, 2, 1024)
> > >>
> > >> I'd like an array of
> > >> (7, 24, 2048)
> > >>
> > >> such that the elements on the last dimension are interleaving the
> > >> elements from the 3rd dimension
> > >>
> > >> [0,0,0,0] -> [0,0,0]
> > >> [0,0,1,0] -> [0,0,1]
> > >> [0,0,0,1] -> [0,0,2]
> > >> [0,0,1,1] -> [0,0,3]
> > >> ...
> > >>
> > >> What might be the simplest way to do this?
> > >
> > > np.transpose(A, (-2, -1)).reshape(A.shape[:-2] + (-1,))
> >
> > I get an error on that 1st transpose:
> >
>
> Transpose needs a slightly different input. If you look at the help, it
> should be clear. The help might also point to np.swapaxes, which may be
> a bit more straight forward for this exact case.

Sorry about that. Was in a rush and working from a faulty memory.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151117/4c53e92d/attachment.html>


More information about the NumPy-Discussion mailing list