[Numpy-discussion] Adding count parameter to unpackbits (PR-10855)

Sebastian Berg sebastian at sipsolutions.net
Thu Feb 21 16:37:52 EST 2019


Hi all,

I was about to merge it, but was noot sure it was really discussed
before (and it would be a long time ago). The pull requests:

https://github.com/numpy/numpy/pull/10855

Proposes to add a count parameter to unpackbits:

``count`` allows subsetting the number of bits that will be unpacked up-front,
rather than reshaping and subsetting later, making the ``packbits`` operation
invertible, and the unpacking less wasteful. Counts larger than the number of
available bits add zero padding. Negative counts trim bits off the end instead
of counting from the beginning. None counts implement the existing behavior of
unpacking everything.

This seems like a pretty small API addition, but I thought I would ping
the list again before merging in case anyone objects to it or feels it
should be modified.

In other words, the count parameter is much the same as indexing the
result:

np.unpackbits(x)[:count]

although it will zero pad if count is out of bounds. Which is necessary
if it is to invert a `np.packbits` when less than 8 bits are packed.

If no one speaks up, I plan to merge it soon.

Best,

Sebastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190221/1349b0f5/attachment.sig>


More information about the NumPy-Discussion mailing list