numpy.packbits() — this is another function for doing binary operations in numpy. It is used to pack the elements of a binary array into bits in a uint8 array. The result is padded to full bytes by adding zero bits at the end.
Syntax: numpy.packbits (arr, axis = None)
arr: [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.If none then packing is done in flattened array.
Return: [packed ndarray] Array of type uint8 whose elements bits represent corresponding to the logical (0 or nonzero) value of the input elements.
Code # 1:
Input array: [[[1 0 1] [0 1 0]] [[1 1 0] [0 0 1]]] Output packed array: [171 16]
Code # 2:
Input array: [[[0 0 1] [1 1 0]] [[1 0 0] [1 1 1]]] Output packed array along axis 1: [[[64 64 128]] [[192 64 64]]]
Executing Data Quality Projects: Ten Steps to Quality Data and Trusted Information (TM), 2nd Edition. Execute Data Quality Projects, Second Edition presents a structured yet flexible approach to cr...
In Learn Python 3 the Hard Way PDF, you'll learn Python by working through 52 brilliantly crafted exercises. Read them. Enter your code exactly. (No copying and pasting!) Correct your mistakes. ...
This book introduces machine learning methods in finance. It features a unified treatment of machine learn...
The role of adaptation, learning and optimization are becoming increasingly essen- tial and intertwined. The capability of a system to adapt either through modification of its physiological structure ...