yt.utilities.lib.bitarray module

Bit array functions

class yt.utilities.lib.bitarray.bitarray

Bases: object

as_bool_array()

Return a copy of this array, as a boolean array.

All of the values encoded in this bitarray are expanded into boolean values in a new array and returned.

Returns:arr – The uint8 values expanded into boolean values
Return type:numpy array of type bool
ibuf
query_value()

Query the on/off value of a given bit.

Return the value encoded in a given index.

Parameters:ind (int) – The index to query in the bitarray.

Examples

>>> arr_in = np.array([True, True, False])
>>> a = ba.bitarray(arr = arr_in)
>>> print a.query_value(2)
set_from_array()

Given an array that is either uint8_t or boolean, set the values of this array to match it.

Parameters:arr (array, castable to uint8) – The array we set from.
set_value()

Set the on/off value of a given bit.

Modify the value encoded in a given index.

Parameters:
  • ind (int) – The index to query in the bitarray.
  • val (bool or uint8_t) – What to set the index to

Examples

>>> arr_in = np.array([True, True, False])
>>> a = ba.bitarray(arr = arr_in)
>>> print a.set_value(2, 1)