Fast functions for manipulating and comparing numpy ndarrays (and recarrays), e.g. efficient NumPy algorithms for solving list-membership problems:
arrayuniqify, recarrayuniqify, equalspairs, recarrayequalspairs, isin, recarrayisin, recarraydifference, arraymax, arraymin
Very fast uniqify routine for numpy arrays.
Parameters
X : numpy array
Determine the unique elements of this numpy array.retainorder : Boolean, optional
Whether or not to return indices corresponding to unique values of X that also sort the values. Default value is False, in which case [D,s] is returned. This can be used to produce a uniqified version of X by simply taking:
X[s][D]or:
X[s[D.nonzero()[0]]]
Returns
D : numpy array
List of “first differences” in the sorted verion of X. Returned when retainorder is False (default).s : numpy array
Permutation that will sort X. Returned when retainorder is False (default).ind : numpy array
List of indices that correspond to unique values of X, without sorting those values. Returned when retainorder is True.
See Also:
Very fast uniqify routine for numpy record arrays (or ndarrays with structured dtype).
Record array version of func:tabular.fast.arrayuniqify.
Parameters
X : numpy recarray
Determine the unique elements of this numpy recarray.retainorder : Boolean, optional
Whether or not to return indices corresponding to unique values of X that also sort the values. Default value is False, in which case [D,s] is returned. This can be used to produce a uniqified version of X by simply taking:
X[s][D]or:
X[s[D.nonzero()[0]]]
Returns
D : numpy recarray
List of “first differences” in the sorted verion of X. Returned when retainorder is False (default).s : numpy array
Permutation that will sort X. Returned when retainorder is False (default).ind : numpy array
List of indices that correspond to unique values of X, without sorting those values. Returned when retainorder is True.
See Also:
Indices of elements in a sorted numpy array equal to those in another.
Given numpy array X and sorted numpy array Y, determine the indices in Y equal to indices in X.
Returns [A,B] where A and B are numpy arrays of indices in X such that:
Y[A[i]:B[i]] = Y[Y == X[i]]`
A[i] = B[i] = 0 if X[i] is not in Y.
Parameters
X : numpy array
Numpy array to compare to the sorted numpy array Y.Y : numpy array
Sorted numpy array. Determine the indices of elements of Y equal to those in numpy array X.
Returns
A : numpy array
List of indices in Y, len(A) = len(Y).B : numpy array
List of indices in Y, len(B) = len(Y).
See Also:
Indices of elements in a sorted numpy recarray (or ndarray with structured dtype) equal to those in another.
Record array version of func:tabular.fast.equalspairs, but slightly different because the concept of being sorted is less well-defined for a record array.
Given numpy recarray X and sorted numpy recarray Y, determine the indices in Y equal to indices in X.
Returns [A,B,s] where s is a permutation of Y such that for:
Y = X[s]
we have:
Y[A[i]:B[i]] = Y[Y == X[i]]
A[i] = B[i] = 0 if X[i] is not in Y.
Parameters
X : numpy recarray
Numpy recarray to compare to the sorted numpy recarray Y.Y : numpy recarray
Sorted numpy recarray. Determine the indices of elements of Y equal to those in numpy array X.
Returns
A : numpy array
List of indices in Y, len(A) = len(Y).B : numpy array
List of indices in Y, len(B) = len(Y).s : numpy array
Permutation of Y.
See Also:
Indices of elements in a numpy array that appear in another.
Fast routine for determining indices of elements in numpy array X that appear in numpy array Y, returning a boolean array Z such that:
Z[i] = X[i] in Y
Parameters
X : numpy array
Numpy array to comapare to numpy array Y. For each element of X, ask if it is in Y.Y : numpy array
Numpy array to which numpy array X is compared. For each element of X, ask if it is in Y.
Returns
b : numpy array (bool)
Boolean numpy array, len(b) = len(X).
See Also:
tabular.fast.recarrayisin(), tabular.fast.arraydifference()
Indices of elements in a numpy record array (or ndarray with structured dtype) that appear in another.
Fast routine for determining indices of elements in numpy record array X that appear in numpy record array Y, returning a boolean array Z such that:
Z[i] = X[i] in Y
Record array version of func:tabular.fast.isin.
Parameters
X : numpy recarray
Numpy recarray to comapare to numpy recarray Y. For each element of X, ask if it is in Y.Y : numpy recarray
Numpy recarray to which numpy recarray X is compared. For each element of X, ask if it is in Y.
Returns
b : numpy array (bool)
Boolean numpy array, len(b) = len(X).
See Also:
Records of a numpy recarray (or ndarray with structured dtype) that do not appear in another.
Fast routine for determining which records in numpy array X do not appear in numpy recarray Y.
Record array version of func:tabular.fast.arraydifference.
Parameters
X : numpy recarray
Numpy recarray to comapare to numpy recarray Y. Return subset of X corresponding to elements not in Y.Y : numpy recarray
Numpy recarray to which numpy recarray X is compared. Return subset of X corresponding to elements not in Y.
Returns
Z : numpy recarray
Subset of X corresponding to elements not in Y.
See Also:
tabular.fast.arraydifference(), tabular.fast.recarrayisin()
Fast “vectorized” max function for element-wise comparison of two numpy arrays.
For two numpy arrays X and Y of equal length, return numpy array Z such that:
Z[i] = max(X[i],Y[i])
Parameters
X : numpy array
Numpy array; len(X) = len(Y).Y : numpy array
Numpy array; len(Y) = len(X).
Returns
Z : numpy array
Numpy array such that Z[i] = max(X[i],Y[i]).
See Also
Fast “vectorized” min function for element-wise comparison of two numpy arrays.
For two numpy arrays X and Y of equal length, return numpy array Z such that:
Z[i] = min(X[i],Y[i])
Parameters
X : numpy array
Numpy array; len(X) = len(Y).Y : numpy array
Numpy array; len(Y) = len(X).
Returns
Z : numpy array
Numpy array such that Z[i] = max(X[i],Y[i]).
See Also