Reputation: 133
This is my simple test code:
data = np.arange(12, dtype='int32').reshape(2,2,3);
so the data is:
array([[[ 0, 1, 2],
[ 3, 4, 5]],
[[ 6, 7, 8],
[ 9, 10, 11]]], dtype=int32)
but why does data.data[:48]
look like this:
'\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\t\x00\x00\x00\n\x00\x00\x00\x0b\x00\x00\x00'
I mean why are '9','10' stored as '\t\x00\x00\x00' and '\n\x00\x00\x00'?
Upvotes: 2
Views: 55
Reputation: 198526
\t
is the tab character, of ASCII value 9. \n
is the LF character, of ASCII value 10. \x00
is a NUL character, of ascii value 0. Thus,
'\t\x00\x00\x00' represents a sequence of bytes [9, 0, 0, 0], which is a little-endian representation of a long integer 9.
'\n\x00\x00\x00' represents a sequence of bytes [10, 0, 0, 0], which is a little-endian representation of a long integer 10.
Upvotes: 3