porepy.utils.setmembership module

Various functions with set operations.

ismember_rows(a, b, sort=True)[source]

Find columns of a that are also members of columns of b.

The function mimics Matlab’s function ismember(…, ‘rows’).

TODO: Rename function, this is confusing!

Parameters
  • a (np.array) – Each column in a will search for an equal in b.

  • b (np.array) – Array in which we will look for a twin

  • sort (boolean, optional) – If true, the arrays will be sorted before seraching, increasing the chances for a match. Defaults to True.

Returns

For each column in a, true if there is a

corresponding column in b.

np.array (int): Indexes so that b[:, ind] is also found in a.

Return type

np.array (boolean)

Examples

>>> a = np.array([[1, 3, 3, 1, 7], [3, 3, 2, 3, 0]])
>>> b = np.array([[3, 1, 3, 5, 3], [3, 3, 2, 1, 2]])
>>> ismember_rows(a, b)
(array([ True,  True,  True,  True, False], dtype=bool), [1, 0, 2, 1])
>>> a = np.array([[1, 3, 3, 1, 7], [3, 3, 2, 3, 0]])
>>> b = np.array([[3, 1, 2, 5, 1], [3, 3, 3, 1, 2]])
>>> ismember_rows(a, b, sort=False)
(array([ True,  True, False,  True, False], dtype=bool), [1, 0, 1])
unique_columns_tol(mat, tol=1e-8)[source]

For an array, remove columns that are closer than a given tolerance.

To uniquify a point set, consider using the function uniquify_point_set instead.

Resembles Matlab’s uniquetol function, as applied to columns. To rather work on rows, use a transpose.

Parameters
  • mat (np.ndarray, nd x n_pts) – Columns to be uniquified.

  • tol (double, optional) – Tolerance for when columns are considered equal. Should be seen in connection with distance between the points in the points (due to rounding errors). Defaults to 1e-8.

Returns

Unique columns. new_2_old: Index of which points that are preserved old_2_new: Index of the representation of old points in the reduced

list.

Return type

np.ndarray

Example

>>> p_un, n2o, o2n = unique_columns(np.array([[1, 0, 1], [1, 0, 1]]))
>>> p_un
array([[1, 0], [1, 0]])
>>> n2o
array([0, 1])
>>> o2n
array([0, 1, 0])
unique_rows(data)[source]

Function similar to Matlab’s unique(…,’rows’)

See also function unique_columns in this module; this is likely slower, but is understandable, documented, and has a tolerance option.

Copied from http://stackoverflow.com/questions/16970982/find-unique-rows-in-numpy-array/ (summary pretty far down on the page) Note: I have no idea what happens here

Parameters

data (ndarray[Any, dtype[float64]]) –

Return type

Tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[int64]], ndarray[Any, dtype[int64]]]

uniquify_point_set(points, tol=1e-8)[source]

Uniquify a set of points so that no two sets of points are closer than a distance tol from each other.

This function partially overlaps the function unique_columns_tol, but the latter is more general, as it provides fast treatment of integer arrays.

FIXME: It should be possible to unify the two implementations, however, more experience is needed before doing so.

Parameters
  • points (np.ndarray, nd x n_pts) – Columns to be uniquified.

  • tol (double, optional) – Tolerance for when columns are considered equal. Should be seen in connection with distance between the points in the point set (due to rounding errors). Defaults to 1e-8.

Returns

Unique columns. new_2_old: Index of which points that are preserved old_2_new: Index of the representation of old points in the reduced

list.

Return type

np.ndarray