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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。