MCPcopy Index your code
hub / github.com/numpy/numpy / test_intersect1d_indices

Method test_intersect1d_indices

numpy/lib/tests/test_arraysetops.py:50–87  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

intersect1dFunction · 0.90
assert_array_equalFunction · 0.90

Tested by

no test coverage detected