(self)
| 44 | assert_array_equal(res, [1, 2, 3]) |
| 45 | |
| 46 | def test_intersect1d_indices(self): |
| 47 | # unique inputs |
| 48 | a = np.array([1, 2, 3, 4]) |
| 49 | b = np.array([2, 1, 4, 6]) |
| 50 | c, i1, i2 = intersect1d(a, b, assume_unique=True, return_indices=True) |
| 51 | ee = np.array([1, 2, 4]) |
| 52 | assert_array_equal(c, ee) |
| 53 | assert_array_equal(a[i1], ee) |
| 54 | assert_array_equal(b[i2], ee) |
| 55 | |
| 56 | # non-unique inputs |
| 57 | a = np.array([1, 2, 2, 3, 4, 3, 2]) |
| 58 | b = np.array([1, 8, 4, 2, 2, 3, 2, 3]) |
| 59 | c, i1, i2 = intersect1d(a, b, return_indices=True) |
| 60 | ef = np.array([1, 2, 3, 4]) |
| 61 | assert_array_equal(c, ef) |
| 62 | assert_array_equal(a[i1], ef) |
| 63 | assert_array_equal(b[i2], ef) |
| 64 | |
| 65 | # non1d, unique inputs |
| 66 | a = np.array([[2, 4, 5, 6], [7, 8, 1, 15]]) |
| 67 | b = np.array([[3, 2, 7, 6], [10, 12, 8, 9]]) |
| 68 | c, i1, i2 = intersect1d(a, b, assume_unique=True, return_indices=True) |
| 69 | ui1 = np.unravel_index(i1, a.shape) |
| 70 | ui2 = np.unravel_index(i2, b.shape) |
| 71 | ea = np.array([2, 6, 7, 8]) |
| 72 | assert_array_equal(ea, a[ui1]) |
| 73 | assert_array_equal(ea, b[ui2]) |
| 74 | |
| 75 | # non1d, not assumed to be uniqueinputs |
| 76 | a = np.array([[2, 4, 5, 6, 6], [4, 7, 8, 7, 2]]) |
| 77 | b = np.array([[3, 2, 7, 7], [10, 12, 8, 7]]) |
| 78 | c, i1, i2 = intersect1d(a, b, return_indices=True) |
| 79 | ui1 = np.unravel_index(i1, a.shape) |
| 80 | ui2 = np.unravel_index(i2, b.shape) |
| 81 | ea = np.array([2, 7, 8]) |
| 82 | assert_array_equal(ea, a[ui1]) |
| 83 | assert_array_equal(ea, b[ui2]) |
| 84 | |
| 85 | def test_setxor1d(self): |
| 86 | a = np.array([5, 7, 1, 2]) |
nothing calls this directly
no test coverage detected