arkouda.util¶
Functions¶
|
|
|
Attach to all objects registered with the names provide |
|
Algorithm to determine shape of broadcasted PD array given two array shapes |
|
|
|
Convert the number of bytes to KB, MB, or GB. |
|
Convert a Categorical array to Strings for display |
|
|
|
Expand an array with values placed into the indicated segments. |
|
|
|
|
|
|
|
Find the inverse of a permutation array. |
|
Check if the dtype of the given array is float. |
|
Check if the dtype of the given array is int. |
|
Check if the dtype of the given array is numeric. |
|
Determine if the name provided is associated with a registered Object |
|
Map values of an array according to an input mapping. |
|
|
|
Register an arkouda object with a user-specified name. Backwards compatible |
|
Register all objects in the provided dictionary |
|
|
|
Helper for summing two sparse matrices together |
|
|
|
Unregister all names provided |
Module Contents¶
- arkouda.util.attach_all(names: list)[source]¶
Attach to all objects registered with the names provide
- Parameters:
names (list) – List of names to attach to
- Return type:
dict
- arkouda.util.broadcast_dims(sa: Sequence[int], sb: Sequence[int]) Tuple[int, Ellipsis] [source]¶
Algorithm to determine shape of broadcasted PD array given two array shapes
see: https://data-apis.org/array-api/latest/API_specification/broadcasting.html#algorithm
- arkouda.util.convert_bytes(nbytes, unit='B')[source]¶
Convert the number of bytes to KB, MB, or GB.
- Parameters:
unit (str, default = "B") – Unit to return. One of {‘B’, ‘KB’, ‘MB’, ‘GB’}.
- Return type:
int
- arkouda.util.convert_if_categorical(values)[source]¶
Convert a Categorical array to Strings for display
- arkouda.util.expand(size, segs, vals)[source]¶
Expand an array with values placed into the indicated segments.
- Parameters:
size (ak.pdarray) – The size of the array to be expanded
segs (ak.pdarray) – The indices where the values should be placed
vals (ak.pdarray) – The values to be placed in each segment
- Returns:
The expanded array.
- Return type:
Notes
This function (with different order of arguments) is now in arkouda proper as ak.broadcast. It is retained here for backwards compatibility.
- arkouda.util.invert_permutation(perm)[source]¶
Find the inverse of a permutation array.
- Parameters:
perm (ak.pdarray) – The permutation array.
- Returns:
The inverse of the permutation array.
- Return type:
ak.array
- arkouda.util.is_float(arry: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical | arkouda.series.Series | arkouda.index.Index)[source]¶
Check if the dtype of the given array is float.
- Parameters:
arry ((pdarray, Strings, Categorical)) – The input pdarray, Strings, or Categorical object.
- Returns:
bool – True if the dtype of pda is of type float, False otherwise.
Example – >>> import arkouda as ak >>> ak.connect() >>> data = ak.array([1.0, 2, 3, 4, np.nan]) >>> is_float(data) True
>>> data2 = ak.arange(5) >>> is_float(data2) False
- arkouda.util.is_int(arry: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical | arkouda.series.Series | arkouda.index.Index)[source]¶
Check if the dtype of the given array is int.
- Parameters:
((pdarray (arry) – The input pdarray, Strings, or Categorical object.
Strings – The input pdarray, Strings, or Categorical object.
Categorical)) – The input pdarray, Strings, or Categorical object.
- Returns:
bool – True if the dtype of pda is of type int, False otherwise.
Example
>>> import arkouda as ak
>>> ak.connect()
>>> data = ak.array([1.0, 2, 3, 4, np.nan])
>>> is_int(data)
False
>>> data2 = ak.arange(5)
>>> is_int(data2)
True
- arkouda.util.is_numeric(arry: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical | arkouda.series.Series | arkouda.index.Index) bool [source]¶
Check if the dtype of the given array is numeric.
- Parameters:
arry ((pdarray, Strings, Categorical)) – The input pdarray, Strings, or Categorical object.
- Returns:
bool – True if the dtype of pda is numeric, False otherwise.
Example – >>> import arkouda as ak >>> ak.connect() >>> data = ak.array([1, 2, 3, 4, 5]) >>> is_numeric(data) True
>>> strings = ak.array(["a", "b", "c"]) >>> is_numeric(strings) False
- arkouda.util.is_registered(name: str, as_component: bool = False) bool [source]¶
Determine if the name provided is associated with a registered Object
- Parameters:
name (str) – The name to check for in the registry
as_component (bool) – Default: False When True, the name will be checked to determine if it is registered as a component of a registered object
- Return type:
bool
- arkouda.util.map(values: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical, mapping: dict | arkouda.Series) arkouda.pdarrayclass.pdarray | arkouda.strings.Strings [source]¶
Map values of an array according to an input mapping.
- Parameters:
values (pdarray, Strings, or Categorical) – The values to be mapped.
mapping (dict or arkouda.Series) – The mapping correspondence.
- Returns:
A new array with the values mapped by the mapping correspondence. When the input Series has Categorical values, the return Series will have Strings values. Otherwise, the return type will match the input type.
- Return type:
- Raises:
TypeError – Raised if arg is not of type dict or arkouda.Series. Raised if values not of type pdarray, Categorical, or Strings.
Examples
>>> import arkouda as ak >>> ak.connect() >>> from arkouda.util import map >>> a = ak.array([2, 3, 2, 3, 4]) >>> a array([2 3 2 3 4]) >>> map(a, {4: 25.0, 2: 30.0, 1: 7.0, 3: 5.0}) array([30.00000000000000000 5.00000000000000000 30.00000000000000000 5.00000000000000000 25.00000000000000000]) >>> s = ak.Series(ak.array(["a","b","c","d"]), index = ak.array([4,2,1,3])) >>> map(a, s) array(['b', 'b', 'd', 'd', 'a'])
- arkouda.util.register(obj, name)[source]¶
Register an arkouda object with a user-specified name. Backwards compatible with earlier arkouda versions.
- arkouda.util.register_all(data: dict)[source]¶
Register all objects in the provided dictionary
- Parameters:
data (dict) – Maps name to register the object to the object. For example, {“MyArray”: ak.array([0, 1, 2])
- Return type:
None
- arkouda.util.sparse_sum_help(idx1, idx2, val1, val2, merge=True, percent_transfer_limit=100)[source]¶
Helper for summing two sparse matrices together
Return is equivalent to ak.GroupBy(ak.concatenate([idx1, idx2])).sum(ak.concatenate((val1, val2)))
- Parameters:
idx1 (pdarray) – indices for the first sparse matrix
idx2 (pdarray) – indices for the second sparse matrix
val1 (pdarray) – values for the first sparse matrix
val2 (pdarray) – values for the second sparse matrix
merge (bool) – If true the indices are combined using a merge based workflow, otherwise they are combine using a sort based workflow.
percent_transfer_limit (int) – Only used when merge is true. This is the maximum percentage of the data allowed to be moved between locales during the merge workflow. If we would exceed this percentage, we fall back to using the sort based workflow.
- Returns:
indices and values for the summed sparse matrix
- Return type:
Examples
>>> idx1 = ak.array([0, 1, 3, 4, 7, 9]) >>> idx2 = ak.array([0, 1, 3, 6, 9]) >>> vals1 = idx1 >>> vals2 = ak.array([10, 11, 13, 16, 19]) >>> ak.util.sparse_sum_help(idx1, inds2, vals1, vals2) (array([0 1 3 4 6 7 9]), array([10 12 16 4 16 7 28]))
>>> ak.GroupBy(ak.concatenate([idx1, idx2])).sum(ak.concatenate((vals1, vals2))) (array([0 1 3 4 6 7 9]), array([10 12 16 4 16 7 28]))