Matrix opreation

2 messages
Open this post in threaded view
|

Matrix opreation

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
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Open this post in threaded view
|

Re: Matrix opreation

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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion