Return the indices of the bins to which each value in input array belongs. ========= ============= ============================ `right` order of bins returned index `i` satisfies ========= ============= ============================ ``False`` increasing ``bins[i-1]
(x, bins, right=False)
| 5665 | |
| 5666 | @array_function_dispatch(_digitize_dispatcher) |
| 5667 | def digitize(x, bins, right=False): |
| 5668 | """ |
| 5669 | Return the indices of the bins to which each value in input array belongs. |
| 5670 | |
| 5671 | ========= ============= ============================ |
| 5672 | `right` order of bins returned index `i` satisfies |
| 5673 | ========= ============= ============================ |
| 5674 | ``False`` increasing ``bins[i-1] <= x < bins[i]`` |
| 5675 | ``True`` increasing ``bins[i-1] < x <= bins[i]`` |
| 5676 | ``False`` decreasing ``bins[i-1] > x >= bins[i]`` |
| 5677 | ``True`` decreasing ``bins[i-1] >= x > bins[i]`` |
| 5678 | ========= ============= ============================ |
| 5679 | |
| 5680 | If values in `x` are beyond the bounds of `bins`, 0 or ``len(bins)`` is |
| 5681 | returned as appropriate. |
| 5682 | |
| 5683 | Parameters |
| 5684 | ---------- |
| 5685 | x : array_like |
| 5686 | Input array to be binned. Prior to NumPy 1.10.0, this array had to |
| 5687 | be 1-dimensional, but can now have any shape. |
| 5688 | bins : array_like |
| 5689 | Array of bins. It has to be 1-dimensional and monotonic. |
| 5690 | right : bool, optional |
| 5691 | Indicating whether the intervals include the right or the left bin |
| 5692 | edge. Default behavior is (right==False) indicating that the interval |
| 5693 | does not include the right edge. The left bin end is open in this |
| 5694 | case, i.e., bins[i-1] <= x < bins[i] is the default behavior for |
| 5695 | monotonically increasing bins. |
| 5696 | |
| 5697 | Returns |
| 5698 | ------- |
| 5699 | indices : ndarray of ints |
| 5700 | Output array of indices, of same shape as `x`. |
| 5701 | |
| 5702 | Raises |
| 5703 | ------ |
| 5704 | ValueError |
| 5705 | If `bins` is not monotonic. |
| 5706 | TypeError |
| 5707 | If the type of the input is complex. |
| 5708 | |
| 5709 | See Also |
| 5710 | -------- |
| 5711 | bincount, histogram, unique, searchsorted |
| 5712 | |
| 5713 | Notes |
| 5714 | ----- |
| 5715 | If values in `x` are such that they fall outside the bin range, |
| 5716 | attempting to index `bins` with the indices that `digitize` returns |
| 5717 | will result in an IndexError. |
| 5718 | |
| 5719 | .. versionadded:: 1.10.0 |
| 5720 | |
| 5721 | `numpy.digitize` is implemented in terms of `numpy.searchsorted`. |
| 5722 | This means that a binary search is used to bin the values, which scales |
| 5723 | much better for larger number of bins than the previous linear search. |
| 5724 | It also removes the requirement for the input array to be 1-dimensional. |
no outgoing calls
searching dependent graphs…