I want to flatten a 2d (n x n) matrix in python into a 1d array, but instead of row major order, I want it to follow the ordering of hilbert curve?
For example, if my input data is 2x2 -->
data[[a b] [c d]]
I want the output to be 1x4 -->
[c, a, b, d]
but I want to do this with an image of say size 256 x 256
Another example is given data
[[12 15 5 0]
[ 3 11 3 7]
[ 9 3 5 2]
[ 4 7 6 8]]
I want the output to be
[ 4 7 3 9 3 12 15 11 3 5 0 7 2 5 6 8]
What is the best way to do this in python?