NumPy字节交换

NumPy字节交换 首页 / Numpy入门教程 / NumPy字节交换

无涯教程已经看到,存储在计算机内存中的数据取决于CPU使用哪种体系结构,它可以是低位或高位。

numpy.ndarray.byteswap()

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']

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

教程推荐

React Native 新架构实战课 -〔蒋宏伟〕

说透低代码 -〔陈旭〕

如何读懂一首诗 -〔王天博〕

To B市场品牌实战课 -〔曹林〕

检索技术核心20讲 -〔陈东〕

说透敏捷 -〔宋宁〕

摄影入门课 -〔小麥〕

JavaScript核心原理解析 -〔周爱民〕

快速上手Kotlin开发 -〔张涛〕

好记忆不如烂笔头。留下您的足迹吧 :)