An offline robot-data cleanup script may replace selected entries with a short repeating sequence. Two calls can use the same input, the same Boolean mask, and the same replacement values yet assign different numbers to every selected position. The difference can come from where the replacement sequence starts and advances.

NumPy's putmask and place both modify target arrays, but their repetition rules describe different mappings. A code review that checks only which entries are selected can miss that distinction. The original seven-entry example below keeps selection fixed and traces the replacement value assigned to each selected location.

Define a synthetic replacement task

Begin with the integer array [100,101,102,103,104,105,106]. Its seven zero-based positions are numbered zero through six. Choose a Boolean mask [False,True,True,False,True,True,False], which selects positions 1,2,4,5. Use replacement values [7,13,19].

These integers are invented data for a representation test. They are not measured robot states, calibrated offsets, or a recommended repair for missing sensor information. The question is simply which replacement number reaches each selected position. Both target arrays will be independent copies so that the first mutation cannot influence the second operation.

The official putmask reference describes assignment by flattened target position and repetition when the values array is shorter than the target [1]. The place reference instead describes consuming values for the selected entries, repeating that sequence when necessary [2]. This fixture makes the distinction visible without relying on the libraries' example arrays.

Trace the position-aligned mapping

For putmask, consider the repeating sequence across all seven original positions: [7,13,19,7,13,19,7]. Apply the mask only after aligning that sequence with the original positions. Position 1 receives 13, position 2 receives 19, position 4 receives 13, and position 5 receives 19.

Positions 0,3,6 keep their original values. The final array is [100,13,19,103,13,19,106]. False mask entries do not restart the replacement sequence or compress its alignment. In this specific three-value example, a selected original position i receives values[i modulo 3].

For place, enumerate only the four selected positions in their existing order. Their selection ranks are zero, one, two, and three. Assign the sequence [7,13,19,7] to those four locations. The final array becomes [100,7,13,103,19,7,106]. A selected entry with selection rank j receives values[j modulo 3].

Those two calculations use different indices in the same remainder operation. One refers to the original storage position; the other refers to the rank within the selected positions. Keeping both index lists visible makes the discrepancy easier to diagnose than comparing only the final arrays.

Execute the comparison

import numpy as np

original = np.arange(100, 107)

mask = np.array([False, True, True, False, True, True, False])

values = np.array([7, 13, 19])

by_position = original.copy()

by_selection = original.copy()

np.putmask(by_position, mask, values)

np.place(by_selection, mask, values)

assert by_position.tolist() == [100, 13, 19, 103, 13, 19, 106]

assert by_selection.tolist() == [100, 7, 13, 103, 19, 7, 106]

The local run used NumPy 2.5.2 and Python 3.14.7. It also checked the two explicit index mappings rather than accepting the arrays solely because they looked plausible:

positions = np.flatnonzero(mask)

np.testing.assert_array_equal(

by_position[mask], values[positions % len(values)])

np.testing.assert_array_equal(

by_selection[mask],

values[np.arange(len(positions)) % len(values)])

All comparisons passed. The original array remained available as the reference because both operations were applied to copies. In this execution both calls returned None; the changed data were in their target arrays, not in a newly returned result.

Change one mask entry as a diagnostic

Now change mask position 1 from True to False, leaving the original values and replacement list unchanged. The selected positions become 2,4,5. Under putmask, position 2 still receives 19 because its original index is still two. The other retained positions likewise keep their position-aligned assignments.

Under place, position 2 is now the first selected location and receives 7, rather than its previous value 13. The new outputs are [100,101,19,103,13,19,106] for putmask and [100,101,7,103,13,19,106] for place.

This change identifies a useful dependency. In the selection-ranked policy, removing an earlier selection can shift later assignments even when those later entries remain selected. In the position-aligned policy shown here, the same earlier mask change does not alter the assignment at an unchanged later position. Neither behavior is a race or a failure to apply the mask.

Do not substitute Boolean assignment without a shape check

The expression target[mask]=values is another operation to examine explicitly. In this fixture there are four selected locations but only three supplied values. The attempted Boolean assignment raises ValueError; it does not automatically implement either of the two repeated sequences above.

That observation concerns these exact shapes. It does not mean every Boolean assignment needs a unique value for every selected element: a scalar assignment is a different case. A replacement helper should declare whether it accepts a scalar, a full array aligned with the source, or a sequence aligned with selected entries.

Two controls that can conceal the distinction

Using a mask that selects all seven positions makes selection rank equal original position. The two methods then agree for the same three-value sequence. A test suite containing only all-True masks would therefore miss the sparse-selection difference demonstrated here.

Supplying the single replacement value 9 is another agreement case. Repetition produces 9 regardless of which index drives it, so both operations assign the same number to every selected position. Passing that scalar-style test does not validate the alignment of a multi-value replacement policy.

Preserve the replacement contract in an audit record

For a reproducible offline transformation, record the source identity, target shape and dtype, selected original positions, replacement sequence, and the index used to align that sequence. Keep an unchanged reference if the review needs to distinguish preserved entries from overwritten entries. This example deliberately uses compatible integer values so that conversion behavior does not obscure the mapping.

The practical check is not merely that positions 1,2,4,5 changed. It is that each one received the replacement assigned by the intended policy. Naming that policy as original-position alignment or selected-position alignment makes a later implementation change reviewable before it alters a robot-data report.

Sources

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

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