March 2003
Intermediate to advanced
656 pages
39h 30m
English
searchsorted
searchsorted(a,values)
a must be a sorted rank
1 array. searchsorted returns
an array of integers s with the same shape
as values. Each element of
s is the index in
a where the corresponding element of
values would fit in the sorted order of
a. For example:
print Numeric.searchsorted([0,1],
[0.2,-0.3,0.5,1.3,1.0,0.0,0.3])
# prints: [1 0 1 2 1 0 1]This specific idiom returns an array with 0 in
correspondence to each element x of
values when x
is less than or equal to 0; 1
when x is greater than
0 and less than or equal to 1;
and 2 when x is greater
than 1. With slight generalization, and with
appropriate thresholds as the elements of sorted array
a, this idiom allows very fast
classification of what subrange each element
x of values
falls into.