numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturns
packbits(a, /, axis=None, bitorder='big')

The result is padded to full bytes by inserting zero bits at the end.

Parameters

a : array_like

An array of integers or booleans whose elements should be packed to bits.

axis : int, optional

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

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

The order of the input bits. 'big' will mimic bin(val), [0, 0, 0, 0, 0, 0, 1, 1] => 3 = 0b00000011 , 'little' will reverse the order so [1, 1, 0, 0, 0, 0, 0, 0] => 3 . Defaults to 'big'.

versionadded

Returns

packed : ndarray

Array of type uint8 whose elements represent bits corresponding to the logical (0 or nonzero) value of the input elements. The shape of packed has the same number of dimensions as the input (unless :None:None:`axis` is None, in which case the output is 1-D).

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

See Also

unpackbits

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

Examples

>>> a = np.array([[[1,0,1],
...  [0,1,0]],
...  [[1,1,0],
...  [0,0,1]]])
... b = np.packbits(a, axis=-1)
... b array([[[160], [ 64]], [[192], [ 32]]], dtype=uint8)

Note that in binary 160 = 1010 0000, 64 = 0100 0000, 192 = 1100 0000, and 32 = 0010 0000.

See :

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 'builtin_function_or_method'>
Commit: