array_correspondence
array_correspondence(A, B, axis=None)
Computes a map from A to the equal elements in B
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A |
(a,) or (a,k) numpy array (must be 1-dim or 2-dim)
|
|
required |
B |
(b,) or (b,k) numpy array (must be 1-dim or 2-dim)
|
|
required |
axis |
int or None, optional (default None)
|
If None, will treat A and B as flat arrays. If a number, will check for equality of the entire axis, in which case the dimension of A and B across that axis must be equal. |
None
|
Returns:
Name | Type | Description |
---|---|---|
f |
(a,) numpy int array
|
index list mapping from A to B, with -1 if there is no
matching entry.
If b contains multiple eligible entries, return an arbitrary one.
If there are no -1s, |
Examples:
Example with simple array correspondence:
>>> A = np.array([1,7,2,7,9,3,7,0])
>>> B = np.array([7,7,3,2,7,8])
>>> f = gpy.array_correspondence(A, B)
>>> f
array([-1, 0, 3, 0, -1, 2, 0, -1])
Example with row correspondence:
>>> A = np.array([[1,3],[5,2],[1,2],[5,2]])
>>> B = np.array([[1,2],[6,9],[5,2]])
>>> f = gpy.array_correspondence(A, B, axis=0)
>>> f
array([-1, 2, 0, 2])
Source code in src/gpytoolbox/array_correspondence.py
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|