[issue35845] Can't read a F-contiguous memoryview in physical order
Stefan Krah
report at bugs.python.org
Mon Jan 28 17:43:30 EST 2019
Stefan Krah <stefan at bytereef.org> added the comment:
Yes, it's modeled after NumPy's tobytes():
>>> x = np.array(list(range(6)), dtype="int8").reshape(2,3)
>>> x.tobytes()
b'\x00\x01\x02\x03\x04\x05'
>>> x.T.tobytes()
b'\x00\x03\x01\x04\x02\x05'
>>>
>>>
>>> memoryview(x).tobytes()
b'\x00\x01\x02\x03\x04\x05'
>>> memoryview(x.T).tobytes()
b'\x00\x03\x01\x04\x02\x05'
I guess the reason is that without a type it's easier to serialize the logical array by default, so you can always assume C when you read back.
NumPy also has an 'F' parameter though that flips the order:
>>> x.tobytes('F')
b'\x00\x03\x01\x04\x02\x05'
It would be possible to add this to memoryview as well.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35845>
_______________________________________
More information about the Python-bugs-list
mailing list