arkouda.pdarraysetops
¶
Module Contents¶
Functions¶
|
Concatenate a list or tuple of |
|
Test whether each element of a 1-D array is also present in a second array. |
|
Returns an integer array of the index values where the values of the first |
|
Find the intersection of two arrays. |
|
Find the set difference of two arrays. |
|
Find the set exclusive-or (symmetric difference) of two arrays. |
|
Find the union of two arrays/List of Arrays. |
- arkouda.pdarraysetops.concatenate(arrays: Sequence[arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | Categorical], ordered: bool = True) arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | Categorical [source]¶
Concatenate a list or tuple of
pdarray
orStrings
objects into onepdarray
orStrings
object, respectively.- Parameters:
arrays (Sequence[Union[pdarray,Strings,Categorical]]) – The arrays to concatenate. Must all have same dtype.
ordered (bool) – If True (default), the arrays will be appended in the order given. If False, array data may be interleaved in blocks, which can greatly improve performance but results in non-deterministic ordering of elements.
- Returns:
Single pdarray or Strings object containing all values, returned in the original order
- Return type:
Union[pdarray,Strings,Categorical]
- Raises:
ValueError – Raised if arrays is empty or if 1..n pdarrays have differing dtypes
TypeError – Raised if arrays is not a pdarrays or Strings python Sequence such as a list or tuple
RuntimeError – Raised if 1..n array elements are dtypes for which concatenate has not been implemented.
Examples
>>> ak.concatenate([ak.array([1, 2, 3]), ak.array([4, 5, 6])]) array([1, 2, 3, 4, 5, 6])
>>> ak.concatenate([ak.array([True,False,True]),ak.array([False,True,True])]) array([True, False, True, False, True, True])
>>> ak.concatenate([ak.array(['one','two']),ak.array(['three','four','five'])]) array(['one', 'two', 'three', 'four', 'five'])
- arkouda.pdarraysetops.in1d(pda1: arkouda.groupbyclass.groupable, pda2: arkouda.groupbyclass.groupable, assume_unique: bool = False, symmetric: bool = False, invert: bool = False) arkouda.pdarrayclass.pdarray | arkouda.groupbyclass.groupable [source]¶
Test whether each element of a 1-D array is also present in a second array.
Returns a boolean array the same length as pda1 that is True where an element of pda1 is in pda2 and False otherwise.
Support multi-level – test membership of rows of a in the set of rows of b.
- Parameters:
a (list of pdarrays, pdarray, Strings, or Categorical) – Rows are elements for which to test membership in b
b (list of pdarrays, pdarray, Strings, or Categorical) – Rows are elements of the set in which to test membership
assume_unique (bool) – If true, assume rows of a and b are each unique and sorted. By default, sort and unique them explicitly.
symmetric (bool) – Return in1d(pda1, pda2), in1d(pda2, pda1) when pda1 and 2 are single items.
invert (bool, optional) – If True, the values in the returned array are inverted (that is, False where an element of pda1 is in pda2 and True otherwise). Default is False.
ak.in1d(a, b, invert=True)
is equivalent to (but is faster than)~ak.in1d(a, b)
.
- Returns:
True for each row in a that is contained in b
Return Type
———— – pdarray, bool
Notes
Only works for pdarrays of int64 dtype, float64, Strings, or Categorical
- arkouda.pdarraysetops.indexof1d(keys: arkouda.groupbyclass.groupable, arr: arkouda.groupbyclass.groupable) arkouda.pdarrayclass.pdarray | arkouda.groupbyclass.groupable [source]¶
Returns an integer array of the index values where the values of the first array appear in the second.
- Parameters:
keys (pdarray or Strings or Categorical) – Input array of values to find the indices of in arr.
arr (pdarray or Strings or Categorical) – The values to search.
- Returns:
The indices of the values of keys in arr.
- Return type:
pdarray, int
- Raises:
TypeError – Raised if either keys or arr is not a pdarray, Strings, or Categorical object
RuntimeError – Raised if the dtype of either array is not supported
- arkouda.pdarraysetops.intersect1d(pda1: arkouda.groupbyclass.groupable, pda2: arkouda.groupbyclass.groupable, assume_unique: bool = False) arkouda.pdarrayclass.pdarray | arkouda.groupbyclass.groupable [source]¶
Find the intersection of two arrays.
Return the sorted, unique values that are in both of the input arrays.
- Parameters:
pda1 (pdarray/Sequence[pdarray, Strings, Categorical]) – Input array/Sequence of groupable objects
pda2 (pdarray/List) – Input array/sequence of groupable objects
assume_unique (bool) – If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.
- Returns:
Sorted 1D array/List of sorted pdarrays of common and unique elements.
- Return type:
pdarray/groupable
- Raises:
TypeError – Raised if either pda1 or pda2 is not a pdarray
RuntimeError – Raised if the dtype of either pdarray is not supported
See also
Notes
ak.intersect1d is not supported for bool or float64 pdarrays
Examples
>>> # 1D Example >>> ak.intersect1d([1, 3, 4, 3], [3, 1, 2, 1]) array([1, 3]) # Multi-Array Example >>> a = ak.arange(5) >>> b = ak.array([1, 5, 3, 4, 2]) >>> c = ak.array([1, 4, 3, 2, 5]) >>> d = ak.array([1, 2, 3, 5, 4]) >>> multia = [a, a, a] >>> multib = [b, c, d] >>> ak.intersect1d(multia, multib) [array([1, 3]), array([1, 3]), array([1, 3])]
- arkouda.pdarraysetops.setdiff1d(pda1: arkouda.groupbyclass.groupable, pda2: arkouda.groupbyclass.groupable, assume_unique: bool = False) arkouda.pdarrayclass.pdarray | arkouda.groupbyclass.groupable [source]¶
Find the set difference of two arrays.
Return the sorted, unique values in pda1 that are not in pda2.
- Parameters:
pda1 (pdarray/Sequence[pdarray, Strings, Categorical]) – Input array/Sequence of groupable objects
pda2 (pdarray/List) – Input array/sequence of groupable objects
assume_unique (bool) – If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.
- Returns:
Sorted 1D array/List of sorted pdarrays of values in pda1 that are not in pda2.
- Return type:
pdarray/groupable
- Raises:
TypeError – Raised if either pda1 or pda2 is not a pdarray
RuntimeError – Raised if the dtype of either pdarray is not supported
See also
Notes
ak.setdiff1d is not supported for bool or float64 pdarrays
Examples
>>> a = ak.array([1, 2, 3, 2, 4, 1]) >>> b = ak.array([3, 4, 5, 6]) >>> ak.setdiff1d(a, b) array([1, 2]) #Multi-Array Example >>> a = ak.arange(1, 6) >>> b = ak.array([1, 5, 3, 4, 2]) >>> c = ak.array([1, 4, 3, 2, 5]) >>> d = ak.array([1, 2, 3, 5, 4]) >>> multia = [a, a, a] >>> multib = [b, c, d] >>> ak.setdiff1d(multia, multib) [array([2, 4, 5]), array([2, 4, 5]), array([2, 4, 5])]
- arkouda.pdarraysetops.setxor1d(pda1: arkouda.groupbyclass.groupable, pda2: arkouda.groupbyclass.groupable, assume_unique: bool = False) arkouda.pdarrayclass.pdarray | arkouda.groupbyclass.groupable [source]¶
Find the set exclusive-or (symmetric difference) of two arrays.
Return the sorted, unique values that are in only one (not both) of the input arrays.
- Parameters:
pda1 (pdarray/Sequence[pdarray, Strings, Categorical]) – Input array/Sequence of groupable objects
pda2 (pdarray/List) – Input array/sequence of groupable objects
assume_unique (bool) – If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.
- Returns:
Sorted 1D array/List of sorted pdarrays of unique values that are in only one of the input arrays.
- Return type:
pdarray/groupable
- Raises:
TypeError – Raised if either pda1 or pda2 is not a pdarray
RuntimeError – Raised if the dtype of either pdarray is not supported
Notes
ak.setxor1d is not supported for bool or float64 pdarrays
Examples
>>> a = ak.array([1, 2, 3, 2, 4]) >>> b = ak.array([2, 3, 5, 7, 5]) >>> ak.setxor1d(a,b) array([1, 4, 5, 7]) #Multi-Array Example >>> a = ak.arange(1, 6) >>> b = ak.array([1, 5, 3, 4, 2]) >>> c = ak.array([1, 4, 3, 2, 5]) >>> d = ak.array([1, 2, 3, 5, 4]) >>> multia = [a, a, a] >>> multib = [b, c, d] >>> ak.setxor1d(multia, multib) [array([2, 2, 4, 4, 5, 5]), array([2, 5, 2, 4, 4, 5]), array([2, 4, 5, 4, 2, 5])]
- arkouda.pdarraysetops.union1d(pda1: arkouda.groupbyclass.groupable, pda2: arkouda.groupbyclass.groupable) arkouda.pdarrayclass.pdarray | arkouda.groupbyclass.groupable [source]¶
Find the union of two arrays/List of Arrays.
Return the unique, sorted array of values that are in either of the two input arrays.
- Parameters:
pda1 (pdarray/Sequence[pdarray, Strings, Categorical]) – Input array/Sequence of groupable objects
pda2 (pdarray/List) – Input array/sequence of groupable objects
- Returns:
Unique, sorted union of the input arrays.
- Return type:
pdarray/groupable
- Raises:
TypeError – Raised if either pda1 or pda2 is not a pdarray
RuntimeError – Raised if the dtype of either array is not supported
See also
Notes
ak.union1d is not supported for bool or float64 pdarrays
Examples
>>> # 1D Example >>> ak.union1d(ak.array([-1, 0, 1]), ak.array([-2, 0, 2])) array([-2, -1, 0, 1, 2]) #Multi-Array Example >>> a = ak.arange(1, 6) >>> b = ak.array([1, 5, 3, 4, 2]) >>> c = ak.array([1, 4, 3, 2, 5]) >>> d = ak.array([1, 2, 3, 5, 4]) >>> multia = [a, a, a] >>> multib = [b, c, d] >>> ak.union1d(multia, multib) [array[1, 2, 2, 3, 4, 4, 5, 5], array[1, 2, 5, 3, 2, 4, 4, 5], array[1, 2, 4, 3, 5, 4, 2, 5]]