[Numpy-discussion] Matrix opreation
Eric Wieser
wieser.eric+numpy at gmail.com
Wed May 23 00:41:38 EDT 2018
I’d recommend asking this kind of question on stackoverflow in future, but
you can do that with:
b = (a
.reshape((2, 2, 4, 4)) # split up the (4,) axis into (2, 2)
.transpose((2, 0, 3, 1)) # reorder to (4, 2, 4, 2)
.reshape((8, 8)) # collapse adjacent dimensions
)
On Tue, 22 May 2018 at 21:31 Yu Peng <ypeng.bj at gmail.com> wrote:
> Hi, I want to make an opreation like this:
>
> if I hava a matrix:
>
> a=
>
> array([[[ 0, 1, 2, 3],
> [ 4, 5, 6, 7],
> [ 8, 9, 10, 11],
> [12, 13, 14, 15]],
>
> [[16, 17, 18, 19],
> [20, 21, 22, 23],
> [24, 25, 26, 27],
> [28, 29, 30, 31]],
>
> [[32, 33, 34, 35],
> [36, 37, 38, 39],
> [40, 41, 42, 43],
> [44, 45, 46, 47]],
>
> [[48, 49, 50, 51],
> [52, 53, 54, 55],
> [56, 57, 58, 59],
> [60, 61, 62, 63]]])
>
>
> and the shape of a is (4,4,4), I want to tranform this tensor or matrix
> to (8,8), and the final result is like this:
> 0 16 1 17 2 18 3 19
> 32 48 33 49 34 50 35 51
> 4 20 5 21 6 22 7 23
> 36 52 37 53 38 54 39 55
> 8 24 9 25 10 26 11 27
> 40 56 41 57 42 58 43 59
> 12 28 13 29 14 30 15 31
> 44 60 45 61 46 62 47 63
> If you know how to deal with this matrix, please give me some
> suggestions.. Thanks.
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180522/daca45e7/attachment-0001.html>
More information about the NumPy-Discussion
mailing list