unpackbits

Contents

unpackbits#

unpackbits(array: ndarray, nof_bits: int) ndarray[source]#

Function found here

Parameters:
  • array (np.ndarray) – Array to unpack

  • nof_bits (int) – Number of bits to unpack

Returns:

Unpacked array

Return type:

np.ndarray

Example

>>> bit_array = np.random.randint(5, size=[3,3])
array([[1, 1, 3],
       [4, 2, 0],
       [4, 3, 2]], dtype=uint8)
>>>
>>> # Unpack 8 bits (8*1, as itemsize of uint8 is 1)
>>> unpackbits(bit_array, 8)
array([[[1, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 0, 0],
        [1, 1, 0, 0, 0, 0, 0, 0]],
       [[0, 0, 1, 0, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0]],
       [[0, 0, 1, 0, 0, 0, 0, 0],
        [1, 1, 0, 0, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0, 0, 0]]], dtype=uint8)