无涯教程已经看到,存储在计算机内存中的数据取决于CPU使用哪种体系结构,它可以是低位或高位。
numpy.ndarray.byteswap()函数在两种表示形式之间切换:bigendian和little-endian。
import numpy as np a = np.array([1, 256, 8755], dtype = np.int16) print 'Our array is:' print a print 'Representation of data in memory in hexadecimal form:' print map(hex,a) # byteswap() 函数通过传递 True 参数就地交换 print 'Applying byteswap() function:' print a.byteswap(True) print 'In hexadecimal form:' print map(hex,a) #我们可以看到正在交换的字节
它将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/numpy/numpy-byte-swapping.html
来源:LearnFk无涯教程网
Our array is: [1 256 8755] Representation of data in memory in hexadecimal form: ['0x1', '0x100', '0x2233'] Applying byteswap() function: [256 1 13090] In hexadecimal form: ['0x100', '0x1', '0x3322']
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)