Digitize Boundary Ownership: Equal Edges and Outside Indices
2026-11-23

Digitize Boundary Ownership: Equal Edges and Outside Indices

Digitize Boundary Ownership determines which interval receives a value equal to a bin edge. NumPy digitize returns interval indices, so the meaning of an index depends on the edge order and the right parameter. The finite examples below use invented scalar values rather than sensor measurements or a fitted probability distribution.

Start with increasing edges and an explicit interval rule

Let the edge array be [2, 5, 9]. With right=False, an interior returned index i satisfies bins[i-1] less than or equal to x and x strictly less than bins[i]. Index 1 therefore represents the interval from 2 inclusive to 5 exclusive. Index 2 represents 5 inclusive to 9 exclusive.

Apply the function to the values [1, 2, 4, 5, 9, 10]. The returned indices are [0, 1, 1, 2, 3, 3]. The value 2 belongs to the interval beginning at 2, while 5 belongs to the next interval beginning at 5. The last edge 9 has no following bounded interval in this edge array.

These outputs are not the positions of matching values inside the input list. The two values 2 and 4 receive the same interval index even though they occupy different input positions. Likewise, the output is not an array of counts per interval; it contains one classification result for each supplied value.

rightFalse[2,5),[5,9);rightTrue(2,5],(5,9].
The interval definitions retain which endpoint includes equality. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

Changing right moves ownership of equal edges

With right=True and the same increasing edges, the interior condition becomes bins[i-1] strictly less than x and x less than or equal to bins[i]. For the same six values, the indices become [0, 0, 1, 1, 2, 3]. The values equal to 2, 5 and 9 move to the side that includes the right edge.

The value 4 remains in interval 1 because it lies strictly between 2 and 5. This makes it a useful control value when reviewing the two modes. The change concerns equality at boundaries, rather than shifting every number or changing the edge locations.

The parameter name can be easy to misread. For increasing edges, right=True includes the right edge of each interior interval. It does not mean that every boundary value is moved toward a larger returned index. In this example the equal-edge indices become smaller when right changes from False to True.

x1,2,4,5,9,10rightFalse0,1,1,2,3,3rightTrue0,0,1,1,2,3.
Outside index zero also needs semantic care before using i-1. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

Outside indices require their own handling

Zero and len(bins) are valid classification outputs for values beyond the bounded interior intervals. Here len(bins) is 3. The caller must not blindly treat every returned index as a valid direct subscript into the three-element edge array, because index 3 lies beyond its final element.

Index 0 also needs semantic care. Reading bins[i-1] would become bins[-1] in Python, which retrieves the last edge rather than an imagined lower edge of the first outside region. A convenient indexing expression can therefore run without an exception while describing the wrong interval.

A clear report labels outside classifications separately before attempting to print bounded interval endpoints. The article does not invent extra edges at infinity or silently discard outside values. Such policies would belong to the consumer's application rather than the returned index alone.

Monotonic edges are part of the contract

The documented interface requires a one-dimensional monotonic edge array and also supports decreasing order with different inequalities. This article keeps the worked arithmetic increasing, so every displayed interval uses one consistent direction. A diagram for decreasing edges would need to restate its conditions rather than copy the increasing table unchanged.

The official implementation checks monotonicity and delegates the lookup to searchsorted with the appropriate side, reversing the edges and adjusting the result for decreasing order. The local test also confirms that a deliberately nonmonotonic edge array is rejected rather than sorted automatically.

Keep edge ownership visible in a result table

For example, a report can mark index 1 as the first bounded interior interval only after stating the active equality rule. Under the default setting its endpoints are written [2,5), whereas under right=True they are written (2,5]. Those bracket choices carry information that the bare index 1 does not contain. Dropping the right setting from a saved result would therefore remove part of the classification definition.

Likewise, changing the edge array after classification would make old indices refer to different intervals. Preserve the original edge values with the output if the result needs later interpretation. This is a reproducibility requirement for the finite example, rather than a claim that digitize stores a copy of its configuration alongside every returned integer.

The useful comparison records each original value beside both returned indices, with the exact edge array and right setting in the caption. This lets a reader verify the three equal-edge cases while retaining interior and outside controls. The table is an original finite example, not a histogram estimated from real observations.

Related explanations appear in the array classification methods section and technical article archive. Primary references are the NumPy digitize documentation and NumPy official implementation.

18028484626 CONTACT US

公司:智联海(惠州)科技有限公司

地址:惠州仲恺高新区陈江街道白云山工业大道 5 号六楼 601

Q Q:18028484626

Copyright © 2002-2026

粤xxx

咨询 在线留言 电话:18028484626
微信 微信扫码添加我