【numpy】利用reshape把三维矩阵变成二维,如何flatten

goal:把(2, 3, 2)的matrix打平成(2, 3*2)的matrix

import numpy as np
x =  np.arange(12).reshape((2, 3, 2))
Out[44]: 
array([[[ 0,  1],
        [ 2,  3],
        [ 4,  5]],

       [[ 6,  7],
        [ 8,  9],
        [10, 11]]])
        
x = x.reshape(x.shape[0],-1)
#x = x.reshape(x.shape[0], 3*2)
Out[47]: 
array([[ 0,  1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10, 11]])

你可能感兴趣的:(tricks,numpy,python,np,matrix,reshape)