Reshape 3-D numpy array to 1-D array:
I would like to reshape a 3-D array that looks like this:
test_3d = np.array([[[0., 0.],
[1., 1.]],
[[2., 2.],
[3., 3.]]])
To a 1-D array that looks like this:
array([0., 1., 2., 3., 0., 1., 2., 3.])
Flattening the array using test_3d.flatten() outputs:
array([0., 0., 1., 1., 2., 2., 3., 3.])
A combination of np.flatten/ravel and transpose functionalities work well for 2-D arrays, but for a 3-D array I get the following:
Input:
test_3d.T.flatten()
Output:
array([0., 2., 1., 3., 0., 2., 1., 3.])
Does anybody have any ideas?
transposetakes an order parameter.. Read its docs and experiment.