Skip to content

Pack / unpack 1-bit 2-bit and 4-bit data in/out of 8-bit numpy arrays.

License

Notifications You must be signed in to change notification settings

telegraphic/numbits

Repository files navigation

numbits

Tests

Pack and unpack 1, 2 and 4 bit data to/from 8-bit numpy arrays

Motivated by radio astronomy, where low bitwidths are common.

Project built with pybind11. Pack/unpack code based on sigpyproc.

Installation

On Unix (Linux, OS X)

You can either:

  • Install numbits from PyPI with:

    pip install numbits

or you can:

  • Clone this repository. and then:

    • Build shared object .so locally, using:

      python setup.py build_ext -i
    • Or install the package globally, using:

      python -m pip install .

      or:

      python setup.py install

Usage

import numpy as np
import numbits
a = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype='uint8')
b = numbits.unpack(a, nbits=2, bitorder="big", parallel=False)

>>> array([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0,
           1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 2, 0], dtype=uint8)

Benchmarks

About

Pack / unpack 1-bit 2-bit and 4-bit data in/out of 8-bit numpy arrays.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •