numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
unpackbits(a, /, axis=None, count=None, bitorder='big')

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 :None:None:`axis` is None ) or the same shape as the input array with unpacking done along the axis specified.

Parameters

a : ndarray, uint8 type

Input array.

axis : int, optional

The dimension over which bit-unpacking is done. None implies unpacking the flattened array.

count : int or None, optional

The number of elements to unpack along :None:None:`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 unpack :None:None:`count` bits. A negative number means to trim off that many bits from the end. None means 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.

versionadded
bitorder : {'big', 'little'}, optional

The 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'.

versionadded

Returns

unpacked : ndarray, uint8 type

The elements are binary-valued (0 or 1).

Unpacks elements of a uint8 array into a binary-valued output array.

See Also

packbits

Packs the elements of a binary-valued array into bits in a uint8 array.

Examples

>>> 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
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.core._multiarray_umath.packbits numpy.packbits

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : None#None
type: <class 'function'>
Commit: