本文简要介绍 python 语言中 numpy.dtype.newbyteorder
的用法。
用法:
dtype.newbyteorder(new_order='S', /)
返回具有不同字节顺序的新 dtype。
数据类型的所有字段和子数组也会进行更改。
- new_order: 字符串,可选
字节顺序强制;来自以下字节顺序规范的值。默认值 (‘S’) 会导致交换当前字节顺序。 new_order 代码可以是以下任何一种:
‘S’ - 将 dtype 从当前交换到相反的字节序
{‘<’, ‘little’} - 小端
{‘>’, ‘big’} - 大端
{‘=’, ‘native’} - 原生订单
{‘|’, ‘I’} - 忽略(不改变字节顺序)
- new_dtype: 类型
具有给定字节顺序更改的新 dtype 对象。
参数:
返回:
注意:
数据类型的所有字段和子数组也会进行更改。
例子:
>>> import sys >>> sys_is_le = sys.byteorder == 'little' >>> native_code = sys_is_le and '<' or '>' >>> swapped_code = sys_is_le and '>' or '<' >>> native_dt = np.dtype(native_code+'i2') >>> swapped_dt = np.dtype(swapped_code+'i2') >>> native_dt.newbyteorder('S') == swapped_dt True >>> native_dt.newbyteorder() == swapped_dt True >>> native_dt == swapped_dt.newbyteorder('S') True >>> native_dt == swapped_dt.newbyteorder('=') True >>> native_dt == swapped_dt.newbyteorder('N') True >>> native_dt == native_dt.newbyteorder('|') True >>> np.dtype('<i2') == native_dt.newbyteorder('<') True >>> np.dtype('<i2') == native_dt.newbyteorder('L') True >>> np.dtype('>i2') == native_dt.newbyteorder('>') True >>> np.dtype('>i2') == native_dt.newbyteorder('B') True
相关用法
- Python numpy dtype.ndim用法及代码示例
- Python numpy dtype.names用法及代码示例
- Python numpy dtype.num用法及代码示例
- Python numpy dtype.name用法及代码示例
- Python numpy dtype.isbuiltin用法及代码示例
- Python numpy dtype.shape用法及代码示例
- Python numpy dtype.alignment用法及代码示例
- Python numpy dtype.__class_getitem__用法及代码示例
- Python numpy dtype.flags用法及代码示例
- Python numpy dtype.fields用法及代码示例
- Python numpy dtype.subdtype用法及代码示例
- Python numpy dtype.descr用法及代码示例
- Python numpy dtype.kind用法及代码示例
- Python numpy dtype.metadata用法及代码示例
- Python numpy dtype.char用法及代码示例
- Python numpy dtype.base用法及代码示例
- Python numpy dtype.byteorder用法及代码示例
- Python numpy dtype.itemsize用法及代码示例
- Python numpy dtype用法及代码示例
- Python numpy diagonal用法及代码示例
- Python numpy divmod用法及代码示例
- Python numpy diagflat用法及代码示例
- Python numpy delete用法及代码示例
- Python numpy dec.setastest用法及代码示例
- Python numpy datetime_as_string用法及代码示例
注:本文由纯净天空筛选整理自numpy.org大神的英文原创作品 numpy.dtype.newbyteorder。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。