Matrix opreation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Matrix opreation

Yu Peng
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:
016117218319
3248334934503551
420521622723
3652375338543955
82492510261127
4056415742584359
1228132914301531
4460456146624763

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
Reply | Threaded
Open this post in threaded view
|

Re: Matrix opreation

Eric Wieser

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:
016117218319
3248334934503551
420521622723
3652375338543955
82492510261127
4056415742584359
1228132914301531
4460456146624763

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