On Tue, Nov 17, 2015 at 3:48 PM, Neal Becker <ndbeck...@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,))

> ------------
> A different question, suppose I just want to stack them
>
> [0,0,0,0] -> [0,0,0]
> [0,0,0,1] -> [0,0,1]
> [0,0,0,2] -> [0,0,2]
> ...
> [0,0,1,0] -> [0,0,1024]
> [0,0,1,1] -> [0,0,1025]
> [0,0,1,2] -> [0,0,1026]
> ...

A.reshape(A.shape[:-2] + (-1,))

--
Robert Kern
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to