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
- count()¶
Count the number of values set in the array.
Examples
>>> arr_in = np.array([True, True, False, True, True, False]) >>> a = ba.bitarray(arr = arr_in) >>> a.count()
- ibuf¶
- logical_and(other, result=None)¶
- logical_or(other, result=None)¶
- logical_xor(other, result=None)¶
- query_value(ind)¶
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(arr)¶
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_range(start, stop, val)¶
Set a range of values to on/off. Uses slice-style indexing.
No return value.
- Parameters:
Examples
>>> arr_in = np.array([True, True, False, True, True, False]) >>> a = ba.bitarray(arr = arr_in) >>> a.set_range(0, 3, 0)
- set_value(ind, val)¶
Set the on/off value of a given bit.
Modify the value encoded in a given index.
- Parameters:
Examples
>>> arr_in = np.array([True, True, False]) >>> a = ba.bitarray(arr = arr_in) >>> print(a.set_value(2, 1))