An offline robot-data report may carry an integer index from one analysis step to another. If the upstream step uses -1 to mean no match, a later array lookup needs to preserve that meaning. Changing an indexing operation to avoid exceptions can instead turn the missing request into a real record, without changing the result's dtype or producing a warning.

NumPy's take function offers several index-handling modes. They describe how an integer addresses array storage, not what that integer means in an application's matching policy. This article uses invented record identifiers to separate those two contracts. No robot command, route execution, or live telemetry is involved.

Define the small record table

Let the one-dimensional records array contain [101,205,309,412]. Its four positions are 0,1,2,3. The numbers stored at those positions are opaque identifiers, not coordinates or numerical measurements. Let the requested positions be [-1,0,3,4], in that order.

Under the report's chosen business rule, only positions from zero through three identify records. The first request represents a missing match; the last lies beyond the table. Positions zero and three are valid. This nonnegative-index policy is an explicit assumption for the example, rather than a restriction imposed by NumPy itself.

The official take reference documents raise, wrap, and clip modes. It specifically notes that clip changes the interpretation of negative indices and that omitting axis selects from the flattened input [1]. Those interface choices are useful, but none should silently replace the report's missing-record policy.

Run the modes on the same requests

import numpy as np

records = np.array([101, 205, 309, 412])

requests = np.array([-1, 0, 3, 4])

clipped = np.take(records, requests, mode='clip')

wrapped = np.take(records, requests, mode='wrap')

assert clipped.tolist() == [101, 101, 412, 412]

assert wrapped.tolist() == [412, 101, 412, 101]

For clip, the request -1 lands on position zero and returns identifier 101. The request 4 lands on position three and returns 412. The output is a perfectly ordinary four-element integer array, but two entries no longer represent valid matches under the stipulated report policy.

For wrap, -1 selects the final position and returns 412, while 4 wraps around to the first position and returns 101. Again, every output value exists in the table. Testing only that returned identifiers are known cannot detect that the input requests were invalid for the application.

These are deliberate numerical examples. They do not establish that clipping or wrapping is universally wrong. A genuinely periodic index domain could intentionally wrap, and an endpoint-extension calculation could intentionally clip. The error here would be applying either convention to a missing-match marker without declaring that conversion.

Raising errors does not define missingness

Calling take on the full requests array with mode='raise' raises IndexError because position 4 is outside this four-element array. However, a separate call with the single request [-1] succeeds and returns [412]. A legitimate negative array index is not automatically an invalid application record identifier.

assert np.take(records, [-1], mode='raise').tolist() == [412]

Consequently, replacing clip with raise catches the upper-bound request in this fixture but does not implement the report's nonnegative-index policy. A test containing only a very large positive index could give false reassurance that every missing marker will now be rejected.

The complete fixture was executed with NumPy 2.5.2 and Python 3.14.7. It separately checked the full-array exception and the successful negative-index call. Keeping those checks separate avoids attributing the exception to the wrong element of the request list.

Check the application's index domain first

For this report, form a validity mask before selecting any rows. Preserve the request positions so that omitted results do not shift their relationship to the original requests.

valid = (requests >= 0) & (requests < len(records))

request_positions = np.flatnonzero(valid)

selected = np.take(records, requests[valid], mode='raise')

assert valid.tolist() == [False, True, True, False]

assert request_positions.tolist() == [1, 2]

assert selected.tolist() == [101, 412]

The output now says that request slots one and two resolved to records 101 and 412. Slots zero and three remain unresolved. A downstream report can retain explicit status fields for those slots instead of filling them with an endpoint record that looks like a successful match.

This example already uses an integer request array. A real ingestion contract must also determine what happens to missing objects, strings, fractional values, or integer-width conversion before this domain check. Silently rounding a fractional request would introduce a different transformation; it is not exercised or recommended by this fixture.

Make intentional clipping visible

NumPy's clip reference defines clipping as replacing values outside an interval with its endpoints [2]. Applying it explicitly to these integer requests with bounds zero and three produces [0,0,3,3]. Taking records at those positions reproduces the earlier clip result exactly.

effective = np.clip(requests, 0, len(records) - 1)

assert effective.tolist() == [0, 0, 3, 3]

assert np.array_equal(np.take(records, effective), clipped)

This equivalence gives an analyst a useful audit view: retain both requested and effective positions when clipping is an intentional policy. It reveals that two requests changed. It does not turn those transformed requests into exact matches or restore the information discarded by replacing them with endpoints.

The example has a nonempty source. An empty table requires its own explicit handling; there is no first or last row to substitute. A helper should establish that condition before constructing bounds from a source length.

Record which axis identifies a row

For an additional shape check, consider [[101,102,103],[201,202,203]]. Calling take with indices [1,0] and no axis returns [102,101], selecting two flattened elements. Specifying axis=0 instead returns the complete rows [[201,202,203],[101,102,103]]. These results answer different questions despite using the same index list.

An auditable selection record therefore identifies the source version, intended axis, request list, validity rule, and any transformed indices. For missing-match workflows, retaining unresolved status is often more informative than producing a fully populated array. The acceptance criterion is that each reported record corresponds to an allowed original request, not merely that the lookup completed.

Sources

[1] NumPy, take: https://numpy.org/doc/stable/reference/generated/numpy.take.html

[2] NumPy, clip: https://numpy.org/doc/stable/reference/generated/numpy.clip.html