本文簡要介紹 python 語言中 numpy.unpackbits
的用法。
用法:
numpy.unpackbits(a, /, axis=None, count=None, bitorder='big')
將 uint8 數組的元素解包為二進製值輸出數組。
的每個元素a表示應解壓縮為二進製值輸出數組的 bit-field。輸出數組的形狀是一維的(如果軸是
None
)或與輸入數組相同的形狀,並沿指定的軸進行解包。- a: ndarray, uint8 類型
輸入數組。
- axis: 整數,可選
完成bit-unpacking 的維度。
None
意味著解壓縮展平的數組。- count: int 或無,可選
要解壓的元素數量軸,作為消除打包大小不是八的倍數的影響的一種方式。非負數表示僅解包數數位。負數意味著從末尾修剪掉那麽多位。
None
表示解壓整個數組(默認)。大於可用位數的計數將向輸出添加零填充。負計數不得超過可用位數。- bitorder: {‘big’, ‘little’},可選
返回位的順序。 ‘big’ 將模仿 bin(val),
3 = 0b00000011 => [0, 0, 0, 0, 0, 0, 1, 1]
,‘little’ 將順序顛倒到[1, 1, 0, 0, 0, 0, 0, 0]
。默認為‘big’。
- unpacked: ndarray, uint8 類型
元素是二進製值(0 或 1)。
參數:
返回:
例子:
>>> a = np.array([[2], [7], [23]], dtype=np.uint8) >>> a array([[ 2], [ 7], [23]], dtype=uint8) >>> b = np.unpackbits(a, axis=1) >>> b array([[0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8) >>> c = np.unpackbits(a, axis=1, count=-3) >>> c array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 1, 0]], dtype=uint8)
>>> p = np.packbits(b, axis=0) >>> np.unpackbits(p, axis=0) array([[0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8) >>> np.array_equal(b, np.unpackbits(p, axis=0, count=b.shape[0])) True
相關用法
- Python numpy union1d用法及代碼示例
- Python numpy unravel_index用法及代碼示例
- Python numpy unique用法及代碼示例
- Python numpy unwrap用法及代碼示例
- Python numpy ufunc.at用法及代碼示例
- Python numpy ufunc.outer用法及代碼示例
- Python numpy ufunc.ntypes用法及代碼示例
- Python numpy ufunc.identity用法及代碼示例
- Python numpy ufunc.reduce用法及代碼示例
- Python numpy ufunc.nin用法及代碼示例
- Python numpy ufunc.nout用法及代碼示例
- Python numpy ufunc.reduceat用法及代碼示例
- Python numpy ufunc.nargs用法及代碼示例
- Python numpy ufunc.types用法及代碼示例
- Python numpy ufunc.signature用法及代碼示例
- Python numpy ufunc.accumulate用法及代碼示例
- Python numpy RandomState.standard_exponential用法及代碼示例
- Python numpy hamming用法及代碼示例
- Python numpy legendre.legint用法及代碼示例
- Python numpy chararray.ndim用法及代碼示例
- Python numpy chebyshev.chebsub用法及代碼示例
- Python numpy chararray.nbytes用法及代碼示例
- Python numpy ma.indices用法及代碼示例
- Python numpy matrix.A1用法及代碼示例
- Python numpy MaskedArray.var用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.unpackbits。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。