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
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 -
2D
X
Y
a
X,Y = np.meshgrid(label_x,label_y) out = np.column_stack((Y.ravel(),X.ravel(),a.ravel()))