Skip to main content

unpackbits

Function unpackbits 

Source
pub fn unpackbits(
    packed: &Array<u8>,
    axis: Option<isize>,
    count: Option<usize>,
    bitorder: Option<&str>,
) -> Result<Array<u8>>
Expand description

Unpack elements of a uint8 array into a binary-valued array

§Parameters

  • packed - Array of type uint8 to be unpacked
  • axis - The dimension along which unpacking is performed. If None, the array is flattened
  • count - The number of elements to unpack along the given axis. If None, unpacks 8 * packed.shape[axis]
  • bitorder - Bit order (‘big’ or ‘little’). ‘big’ means the most significant bit is at the beginning

§Returns

The unpacked array with binary values

§Examples

use numrs2::prelude::*;

// Unpack uint8 array
let packed = Array::from_vec(vec![163u8]); // 10100011 in binary
let unpacked = unpackbits(&packed, None, None, Some("big")).expect("operation should succeed");
assert_eq!(unpacked.to_vec(), vec![1, 0, 1, 0, 0, 0, 1, 1]);

// Unpack with specific count
let packed = Array::from_vec(vec![224u8]); // 11100000 in binary
let unpacked = unpackbits(&packed, None, Some(3), Some("big")).expect("operation should succeed");
assert_eq!(unpacked.to_vec(), vec![1, 1, 1]);