From c2de04da9b0feb2853b9814c7953aa51a29a058e Mon Sep 17 00:00:00 2001 From: mattip Date: Wed, 13 Feb 2019 18:14:05 +0200 Subject: ENH: add 'order' keyword to packbits, unpackbits --- numpy/core/multiarray.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'numpy/core/multiarray.py') diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py index a839ae402..8ea71cde4 100644 --- a/numpy/core/multiarray.py +++ b/numpy/core/multiarray.py @@ -8,6 +8,7 @@ by importing from the extension module. import functools import warnings +import sys from . import overrides from . import _multiarray_umath @@ -1113,7 +1114,7 @@ def putmask(a, mask, values): @array_function_from_c_func_and_dispatcher(_multiarray_umath.packbits) -def packbits(a, axis=None): +def packbits(a, axis=None, order='big'): """ packbits(a, axis=None) @@ -1129,6 +1130,11 @@ def packbits(a, axis=None): axis : int, optional The dimension over which bit-packing is done. ``None`` implies packing the flattened array. + order : 'big' or 'little', only the first letter is checked + The order of the returned bits. The default is the common standard + where 3 => [0, 0, 0, 0, 0, 1, 1] + + .. versionadded:: 1.17.0 Returns ------- @@ -1164,7 +1170,7 @@ def packbits(a, axis=None): @array_function_from_c_func_and_dispatcher(_multiarray_umath.unpackbits) -def unpackbits(a, axis=None, count=None): +def unpackbits(a, axis=None, count=None, order='big'): """ unpackbits(a, axis=None, count=None) @@ -1194,6 +1200,12 @@ def unpackbits(a, axis=None, count=None): .. versionadded:: 1.17.0 + order : 'big' or 'little', only the first letter is checked + The order of the returned bits. The default is the common standard + where 3 => [0, 0, 0, 0, 0, 1, 1] + + .. versionadded:: 1.17.0 + Returns ------- unpacked : ndarray, uint8 type -- cgit v1.2.1 From fa709605401b5acde6fa515239ba29a548c53755 Mon Sep 17 00:00:00 2001 From: mattip Date: Wed, 27 Feb 2019 17:28:35 +0200 Subject: BUG: parametrize tests, fix for interaction of count, order --- numpy/core/multiarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/core/multiarray.py') diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py index 8ea71cde4..e9e066bea 100644 --- a/numpy/core/multiarray.py +++ b/numpy/core/multiarray.py @@ -1132,7 +1132,7 @@ def packbits(a, axis=None, order='big'): ``None`` implies packing the flattened array. order : 'big' or 'little', only the first letter is checked The order of the returned bits. The default is the common standard - where 3 => [0, 0, 0, 0, 0, 1, 1] + where [0, 0, 0, 0, 0, 1, 1] => 3 .. versionadded:: 1.17.0 -- cgit v1.2.1 From b415ffad5327c5ff656b94c6aaf683209c9c8104 Mon Sep 17 00:00:00 2001 From: mattip Date: Wed, 13 Mar 2019 10:05:40 +0200 Subject: ENH: changes from review --- numpy/core/multiarray.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'numpy/core/multiarray.py') diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py index e9e066bea..78fec1aab 100644 --- a/numpy/core/multiarray.py +++ b/numpy/core/multiarray.py @@ -1114,7 +1114,7 @@ def putmask(a, mask, values): @array_function_from_c_func_and_dispatcher(_multiarray_umath.packbits) -def packbits(a, axis=None, order='big'): +def packbits(a, axis=None, bitorder='big'): """ packbits(a, axis=None) @@ -1130,9 +1130,11 @@ def packbits(a, axis=None, order='big'): axis : int, optional The dimension over which bit-packing is done. ``None`` implies packing the flattened array. - order : 'big' or 'little', only the first letter is checked - The order of the returned bits. The default is the common standard - where [0, 0, 0, 0, 0, 1, 1] => 3 + bitorder : {'big', 'little'}, optional + The order of the input bits. 'big' will mimic bin(val), + ``[0, 0, 0, 0, 0, 0, 1, 1] => 3 = 0b00000011 => ``, 'little' will + reverse the order so ``[1, 1, 0, 0, 0, 0, 0, 0] => 3``. + Defaults to 'big'. .. versionadded:: 1.17.0 @@ -1170,7 +1172,7 @@ def packbits(a, axis=None, order='big'): @array_function_from_c_func_and_dispatcher(_multiarray_umath.unpackbits) -def unpackbits(a, axis=None, count=None, order='big'): +def unpackbits(a, axis=None, count=None, bitorder='big'): """ unpackbits(a, axis=None, count=None) @@ -1200,9 +1202,11 @@ def unpackbits(a, axis=None, count=None, order='big'): .. versionadded:: 1.17.0 - order : 'big' or 'little', only the first letter is checked - The order of the returned bits. The default is the common standard - where 3 => [0, 0, 0, 0, 0, 1, 1] + bitorder : {'big', 'little'}, optional + The order of the returned bits. 'big' will mimic bin(val), + ``3 = 0b00000011 => [0, 0, 0, 0, 0, 0, 1, 1]``, 'little' will reverse + the order to ``[1, 1, 0, 0, 0, 0, 0, 0]``. + Defaults to 'big'. .. versionadded:: 1.17.0 -- cgit v1.2.1