![](/img/trans.png)
[英]How should I get the corresponding real numpy dtype for a complex dtype?
[英]How to get endianness of numpy dtype
给定一个数组
x = np.arange(3)
我可以通过这样做获得字节顺序
>>> x.dtype.byteorder
'='
如何判断这是大端还是小端? 我想得到'<'
, '>'
或'|'
作为输出,而不是'='
。
为了清楚起见,我不会挂断信息的格式。我只想知道“大端”,“小端”或“无关”,但我不在乎它是否是“原生”。
可能只需检查sys.byteorder
。 甚至文档中的numpy.dtype.byteorder
示例也使用sys.byteorder
来确定本机的内容。
endianness_map = {
'>': 'big',
'<': 'little',
'=': sys.byteorder,
'|': 'not applicable',
}
你可以交换两次endianness使numpy显示真正的endianness:
dtype_nonnative = dtype.newbyteorder('S').newbyteorder('S')
dtype_nonnative.byteorder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.