Warning
This page was created from a pull request.
jax.numpy.unpackbits¶
-
jax.numpy.
unpackbits
(a, axis=None, count=None, bitorder='big')[source]¶ Unpacks elements of a uint8 array into a binary-valued output array.
LAX-backend implementation of
unpackbits()
. Original docstring below.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 axis is
None
) or the same shape as the input array with unpacking done along the axis specified.- Returns
- unpackedndarray, uint8 type
The elements are binary-valued (0 or 1).
- packbitsPacks the elements of a binary-valued array into bits in
a uint8 array.
>>> 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