bundles / numpy 2.4.3 / numpy / unpackbits
_ArrayFunctionDispatcher
numpy:unpackbits
Signature
def unpackbits ( a , / , axis = None , count = None , bitorder = big ) Summary
Unpacks elements of a uint8 array into a binary-valued output array.
Extended Summary
Each element of a represents a bit-field that should be unpacked into a binary-valued output array. The shape of the output array is either 1-D (if axis is None) or the same shape as the input array with unpacking done along the axis specified.
Parameters
a: ndarray, uint8 typeInput array.
axis: int, optionalThe dimension over which bit-unpacking is done.
Noneimplies unpacking the flattened array.count: int or None, optionalThe number of elements to unpack along
axis, provided as a way of undoing the effect of packing a size that is not a multiple of eight. A non-negative number means to only unpackcountbits. A negative number means to trim off that many bits from the end.Nonemeans to unpack the entire array (the default). Counts larger than the available number of bits will add zero padding to the output. Negative counts must not exceed the available number of bits.bitorder: {'big', 'little'}, optionalThe order of the returned bits. 'big' will mimic bin(val),
3 = 0b00000011 => [0, 0, 0, 0, 0, 0, 1, 1], 'little' will reverse the order to[1, 1, 0, 0, 0, 0, 0, 0]. Defaults to 'big'.
Returns
unpacked: ndarray, uint8 typeThe elements are binary-valued (0 or 1).
Examples
import numpy as np a = np.array([[2], [7], [23]], dtype=np.uint8) a b = np.unpackbits(a, axis=1) b c = np.unpackbits(a, axis=1, count=-3) c✓
p = np.packbits(b, axis=0) np.unpackbits(p, axis=0) np.array_equal(b, np.unpackbits(p, axis=0, count=b.shape[0]))✓
See also
- packbits
Packs the elements of a binary-valued array into bits in a uint8 array.
Aliases
-
numpy.unpackbits