In python, I would like to flatten an array that are 3 dimensional. Say shape (10, 15, 200). But the first two would need to be flattened with row-major order while the remaining flatten operation would be done in column-major order.
I can probably do this in a for loop by iterating over operations like slicing the array, flattening it individually, and storing it in the main array. For example, I would slice the main array to be (10, 15) do a row-major flatten --> store it to the main with (150, 200), and then do a column-major flatten operation.
I am not sure if this is the most efficient method of doing this. Is there a better way to do this using numpy calls?
First use
.reshapewith the default"C"ordering (row-major) on the first two dimensions and then use.flattenwith the"F"ordering (column-major) for the final result.Result: