Related to Determine the endianness of a numpy array
Given an array
x = np.arange(3)
I can get the byte order by doing
>>> x.dtype.byteorder
'='
How do I find out if this is big or little endian? I would like to get '<'
, '>'
or '|'
as the output, not '='
.
To be clear, I am not hung up on what format the information comes in. I just want to know "big endian", "little endian" or "irrelevant", but I don't care if it's "native" or not.
Probably just check sys.byteorder
. Even the numpy.dtype.byteorder
examples in the docs use sys.byteorder
to determine what's native.
endianness_map = {
'>': 'big',
'<': 'little',
'=': sys.byteorder,
'|': 'not applicable',
}
You can swap the endianness twice to make numpy reveal the true endianness:
dtype_nonnative = dtype.newbyteorder('S').newbyteorder('S')
dtype_nonnative.byteorder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With