numpy.ndarray.byteswap()函数通过返回字节包装的数组(可选地就地交换)在低端和大端数据表示之间切换。
用法: ndarray.byteswap(inplace=False)
参数:
inplace:[bool,可选]如果为True,就地交换字节,默认值为False。
返回:
out :[ndarray]字节数组。如果inplace为True,则这是对自身的看法。
代码1:
# Python program explaining
# byteswap() function
import numpy as geek
# a is an array of integers.
a = geek.array([1, 256, 100], dtype = np.int16)
print(a.byteswap(True))
输出:
[256 1 25600]
代码2: byteswap()
函数不适用于字符串数组。
# Python program explaining
# byteswap() function
import numpy as geek
# a is an array of strings
a = geek.array(["arka","soumen","simran"],dtype = np.int16)
print(a.byteswap(True))
输出:
ValueError Traceback (most recent call last)in () 1 import numpy as geek ----> 2 a = geek.array(["arka","soumen","simran"],dtype = np.int16) 3 4 #a is an array of strings 5 ValueError: invalid literal for int() with base 10: 'arka'
相关用法
注:本文由纯净天空筛选整理自ArkadipGhosh大神的英文原创作品 numpy.ndarray.byteswap() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。