Skip to main content
`Ctrl`+`K`

# numpy.dtype.byteorder

attribute

dtype.byteorder

  A character indicating the byte-order of this data-type object.

  One of:

  ‘=’ | native
  ‘<’ | little-endian
  ‘>’ | big-endian
  ‘|’ | not applicable

  All built-in data-type objects have byteorder either ‘=’ or ‘|’.

  Examples

      >>> import numpy as np
      >>> dt = np.dtype(np.int16)
      >>> dt.byteorder
      '='
      >>> # endian is not relevant for 8 bit numbers
      >>> np.dtype(np.int8).byteorder
      '|'
      >>> # or ASCII strings
      >>> np.dtype('S2').byteorder
      '|'
      >>> # Even if specific code is given, and it is native
      >>> # '=' is the byteorder
      >>> import sys
      >>> sys_is_le = sys.byteorder == 'little'
      >>> native_code = '<' if sys_is_le else '>'
      >>> swapped_code = '>' if sys_is_le else '<'
      >>> dt = np.dtype(native_code + 'i2')
      >>> dt.byteorder
      '='
      >>> # Swapped code shows up as itself
      >>> dt = np.dtype(swapped_code + 'i2')
      >>> dt.byteorder == swapped_code
      True