Flatten numpy array without double for loop

后端 未结 1 1384
天涯浪人
天涯浪人 2020-12-12 05:32

I have a 2-d matrix. For the purposes of this example, let\'s say it is a random matrix

>>> a = np.random.randn(5, 7)
>>> a
array([[-0.3727         


        
相关标签:
1条回答
  • 2020-12-12 05:43

    Use np.meshgrid to create 2D meshes corresponding to X and Y labels and then stack them as columns alongwith the 2D input array a, like so -

    X,Y = np.meshgrid(label_x,label_y)
    out = np.column_stack((Y.ravel(),X.ravel(),a.ravel()))
    
    0 讨论(0)
提交回复
热议问题