Two robot commissioning logs can contain the same machine ID for different reasons. A station may record an asset twice because two checks ran on it, because it retried an inspection, or because the export duplicated a row. An intersection should identify the IDs observed in both logs. Treating each input as already unique when it contains repetitions can produce a result that includes an ID found in only one source.
The example uses invented integer IDs and was executed with NumPy 2.5.2. The records stand for commissioning events. They carry no real asset identifiers or claims about the state of production equipment.
Start with a set of shared IDs
Log A contains IDs 7, 7, and 11. Log B contains 11 and 20. A correct intersection returns 11. NumPy's intersect1d can also report an index into each input. With repeated IDs and default settings, the index refers to the first occurrence of that ID in its input. These indices can point to representative source records when first occurrence is the rule the report requires.
import numpy as np
log_a = np.array([7, 7, 11])
log_b = np.array([11, 20])
shared, index_a, index_b = np.intersect1d(
log_a, log_b, return_indices=True
)
assert shared.tolist() == [11]
assert index_a.tolist() == [2]
assert index_b.tolist() == [0]
The output is sorted by ID. Its order does not express when each machine appeared, whether either inspection succeeded, or which observation should be kept if the shared ID has several rows. Record those other properties separately from the set of shared IDs.
See what changes when uniqueness is assumed
The assume_unique option allows the routine to proceed with the premise that every input element is unique within its own array. The NumPy documentation warns that giving it non-unique input can produce incorrect values and indices. The following call deliberately violates that premise.
invalid_shared, invalid_a, invalid_b = np.intersect1d(
log_a, log_b, assume_unique=True, return_indices=True
)
In the executed version, invalid_shared contained [7, 11], even though log B has no 7. The reported indices for log B were [-2, 0]. A negative index in NumPy can silently address a real row, so using that index against a two-element array would retrieve the first row. It would associate the bogus shared value 7 with a log B row whose actual ID is 11. These particular outputs are observations from the fixture. The documented warning applies whenever the uniqueness assumption is false, even if a different version or input shape produces another symptom.
Check repetition where the data enters the comparison
If each log should have exactly one row per ID, inspect the counts before treating the input as a set of eligible records. NumPy's unique can return each distinct value together with its number of occurrences. Run the check on each ID array independently. Matching lengths across two files says nothing about duplicate IDs inside either one.
ids_a, counts_a = np.unique(log_a, return_counts=True)
ids_b, counts_b = np.unique(log_b, return_counts=True)
assert ids_a[counts_a > 1].tolist() == [7]
assert ids_b[counts_b > 1].tolist() == []
An import that requires exactly one row per ID can report the duplicate with references back to the input rows. If it deliberately chooses one row per ID, document the selection rule. It might choose the earliest inspection, the latest valid result, or a record matched by both ID and check type. A default first occurrence is useful only when it has the desired meaning. When both reports can have multiple eligible events per machine, use a record join designed to preserve those events. An ID set alone does not encode that relationship.
Keep the ID representation stable
An integer is appropriate for the synthetic IDs. In another system, the displayed ID may be a string with leading zeros, or the same number may be used in multiple plants. Converting an identifier to an integer can collapse distinct strings. Choose the same ID type and scope for both sources before comparing them. If equipment IDs are unique only within a site, include the site in the matching key. Preserve missing identifiers separately so a placeholder cannot become a shared asset.
Before writing a report based on returned indices, validate that they are in the expected forward range and that selecting those rows gives the same ID from both input arrays. Verify that the order of the other columns has stayed aligned with the key arrays. These checks can catch a mismatch in record selection, while the input count check addresses whether the uniqueness premise was valid.
For the valid example, the reconstructed IDs agree on both sides. When checks consume externally prepared indices, test the shape and the range before selecting rows. The range check includes the lower bound so that negative positions cannot be interpreted as offsets from the end.
assert np.all((index_a >= 0) & (index_a < len(log_a)))
assert np.all((index_b >= 0) & (index_b < len(log_b)))
assert np.array_equal(log_a[index_a], shared)
assert np.array_equal(log_b[index_b], shared)
A regression test can place a duplicate ID only in the left input, then repeat a genuinely shared ID to verify the first-occurrence rule. Add a case in which no IDs overlap, and compare the shared values with an independently computed intersection of the two ID sets. Test that rows flagged as repeated remain available for review. That keeps the reconciliation result separate from the decision about which events count as the authoritative record.
Sources checked November 28, 2026
NumPy, numpy.intersect1d
https://numpy.org/doc/stable/reference/generated/numpy.intersect1d.html
NumPy, numpy.unique
https://numpy.org/doc/stable/reference/generated/numpy.unique.html
Illustration. AI-generated concept contrasting a repeated ID in one robot log with a shared ID present in both logs.