I am trying to understand what is happening in python when you perform some operations. For instance, from this reply, I understand how strides are working and how it is important. But now, I would like to know, if after transpose, in the memory, the data haven't been 'physically' transposed, when I am calling .flatten(order="C")
after a transpose operation, the data is correctly ordered. Thanks to the strides I know it is definitely possible to implement this operation, unfortunately I can't come up with an algorithm that works for any 'transposed' strides.
import numpy as np
array = np.arange(24).reshape(2, 3, 4)
print(array.flatten(order='C'))
array = array.transpose(1, 0, 2)
print(array.flatten(order='C'))
>>> [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]
>>> [ 0 1 2 3 12 13 14 15 4 5 6 7 16 17 18 19 8 9 10 11 20 21 22 23]