Find indices where elements should be inserted to maintain order. Find the indices into a sorted array `a` such that, if the corresponding elements in `v` were inserted before the indices, the order of `a` would be preserved. Assuming that `a` is sorted: ====== =========
(a, v, side='left', sorter=None)
| 1458 | |
| 1459 | @array_function_dispatch(_searchsorted_dispatcher) |
| 1460 | def searchsorted(a, v, side='left', sorter=None): |
| 1461 | """ |
| 1462 | Find indices where elements should be inserted to maintain order. |
| 1463 | |
| 1464 | Find the indices into a sorted array `a` such that, if the |
| 1465 | corresponding elements in `v` were inserted before the indices, the |
| 1466 | order of `a` would be preserved. |
| 1467 | |
| 1468 | Assuming that `a` is sorted: |
| 1469 | |
| 1470 | ====== ============================ |
| 1471 | `side` returned index `i` satisfies |
| 1472 | ====== ============================ |
| 1473 | left ``a[i-1] < v <= a[i]`` |
| 1474 | right ``a[i-1] <= v < a[i]`` |
| 1475 | ====== ============================ |
| 1476 | |
| 1477 | Parameters |
| 1478 | ---------- |
| 1479 | a : 1-D array_like |
| 1480 | Input array. If `sorter` is None, then it must be sorted in |
| 1481 | ascending order, otherwise `sorter` must be an array of indices |
| 1482 | that sort it. |
| 1483 | v : array_like |
| 1484 | Values to insert into `a`. |
| 1485 | side : {'left', 'right'}, optional |
| 1486 | If 'left', the index of the first suitable location found is given. |
| 1487 | If 'right', return the last such index. If there is no suitable |
| 1488 | index, return either 0 or N (where N is the length of `a`). |
| 1489 | sorter : 1-D array_like, optional |
| 1490 | Optional array of integer indices that sort array a into ascending |
| 1491 | order. They are typically the result of argsort. |
| 1492 | |
| 1493 | Returns |
| 1494 | ------- |
| 1495 | indices : int or array of ints |
| 1496 | Array of insertion points with the same shape as `v`, |
| 1497 | or an integer if `v` is a scalar. |
| 1498 | |
| 1499 | See Also |
| 1500 | -------- |
| 1501 | sort : Return a sorted copy of an array. |
| 1502 | histogram : Produce histogram from 1-D data. |
| 1503 | |
| 1504 | Notes |
| 1505 | ----- |
| 1506 | Binary search is used to find the required insertion points. |
| 1507 | |
| 1508 | As of NumPy 1.4.0 `searchsorted` works with real/complex arrays containing |
| 1509 | `nan` values. The enhanced sort order is documented in `sort`. |
| 1510 | |
| 1511 | This function uses the same algorithm as the builtin python |
| 1512 | `bisect.bisect_left` (``side='left'``) and `bisect.bisect_right` |
| 1513 | (``side='right'``) functions, which is also vectorized |
| 1514 | in the `v` argument. |
| 1515 | |
| 1516 | Examples |
| 1517 | -------- |
nothing calls this directly
no test coverage detected
searching dependent graphs…