distribute_in_zones¶
- emlib.misc.distribute_in_zones(x, split_points, side='left')[source]¶
Returns the index of a “zone” where to place x.
A zone is a numeric range defined by an inclusive lower boundary and a non-inclusive higher boundary
NB: see
distribute_in_zones_right()
for a non-inclusive lower and inclusive upper boundary. The edge zones extend to inf.- Parameters:
x (
Union
[float
,Rational
]) – the number to assign a zone tosplit_points (
Sequence
[Union
[Rational
,float
]]) – the split points which define the zonesside – if “left”, a zone has an inclusive lower bound and a non-inclusive upper bound. “right” is the opposite
- Return type:
int
- Returns:
the index of the zone
Example:
# 1 and 5 define three zones: (-inf, 1], (1, 5], (5, inf) >>> distribute_in_zones(2, [1, 5]) 1 >>> distribute_in_zones(5, [1, 5]) 2