pyyeti.locate.mat_intersect¶
- pyyeti.locate.mat_intersect(D1, D2, keep=0)[source]¶
Get row intersection partition vectors between two matrices or vectors.
- Parameters:
D1 (array_like) – 1d or 2d array.
D2 (array_like) – 1d or 2d array.
keep (integer) –
0, 1 or 2:
if 0, loop over smaller matrix, finding where the rows occur in the larger
if 1, loop over D1, finding where the rows occur in D2
if 2, loop over D2, finding where the rows occur in D1
- Returns:
pv1 (1d ndarray) – Row index vector into D1.
pv2 (1d ndarray) – Row index vector into D2.
Notes
pv1 and pv2 are found such that:
D1[pv1] == D2[pv2] (Note for matrices: M[i] == M[i, :])
For matrices, the number of columns in D1 and D2 must be equal to get non-empty results.
Examples
>>> import numpy as np >>> from pyyeti import locate >>> mat1 = np.array([[7, 3], [6, 8], [4, 0], [9, 2], [1, 5]]) >>> mat2 = np.array([[9, 2], [1, 5], [7, 3]]) >>> pv1, pv2 = locate.mat_intersect(mat1, mat2) >>> pv1 array([3, 4, 0]...) >>> pv2 array([0, 1, 2]...) >>> np.all(mat1[pv1] == mat2[pv2]) True >>> locate.mat_intersect(mat1, mat2, 1) (array([0, 3, 4]...), array([2, 0, 1]...)) >>> locate.mat_intersect(mat2, mat1, 2) (array([2, 0, 1]...), array([0, 3, 4]...)) >>> locate.mat_intersect(mat2, mat1) (array([0, 1, 2]...), array([3, 4, 0]...)) >>> mat3 = np.array([[1, 2, 3]]) >>> locate.mat_intersect(mat1, mat3) (array([], dtype=int...), array([], dtype=int...)