python flatten 3d array to 2d