numpy.unpackbits()

numpy.unpackbits(myarray, axis=None)

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

Each element of myarray 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.

Parameters:

myarray : ndarray, uint8 type

Input array.

axis : int, optional

Unpacks along this axis.

Returns:

unpacked : ndarray, uint8 type

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

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)
doc_NumPy
2017-01-10 18:19:08
Comments
Leave a Comment

Please login to continue.