sdr.pack(x: ArrayLike, bpe: int, dtype: DTypeLike | None = None) NDArray[int_]

Packs a binary array into an array with multiple bits per element.

The data is assumed to have the most significant bit first. If there are not enough bits in the input array to fill the last element of the output array, the remaining bits are filled with zeros.

Parameters:
x: ArrayLike

The input binary array with 1 bit per element.

bpe: int

The number of bits per element in the output array.

dtype: DTypeLike | None = None

The data type of the output array. If None, the smallest unsigned integer dtype that can hold bpe bits is used.

Returns:

The packed data with bpe bits per element.

Examples

In [1]: sdr.pack([1, 0, 0, 0, 1, 1, 0, 1], 2)
Out[1]: array([2, 0, 3, 1], dtype=uint8)

In [2]: sdr.pack([1, 0, 0, 0, 1, 1, 0, 1], 3)
Out[2]: array([4, 3, 2], dtype=uint8)