Complete worked example
python
import numpy as np
def inspect_example(values, low, high):
data = np.asarray(values, dtype=np.float64)
if data.ndim != 1 or not np.isfinite([low, high]).all() or low > high:
raise ValueError("expected a vector and ordered finite bounds")
mask = np.isfinite(data) & (data >= low) & (data < high)
return data[mask]- Reasoning
- The worked example first converts a vector to float64 and validates that both bounds are finite and correctly ordered. It builds one combined mask from isfinite and the two comparisons, then selects data[mask]. That final indexing operation produces a new array. Missing values represented as None become NaN during the explicit numeric conversion and are excluded rather than counted as zero. The boolean array and numerical values have equal shape. Inspect them side by side for a small example: each True retains the value at the same coordinate. A mask with a different length is not an invitation to guess alignment; it violates the indexing contract.