nlcpy.digitize
- nlcpy.digitize(x, bins, right=False)
Return is the indices of the bins to which each value in input array belongs.
right
order of bins
returned index i satisfies
Falseincreasing
bins[i-1] <= x < bins[i]Trueincreasing
bins[i-1] < x <= bins[i]Falsedecreasing
bins[i-1] < x <= bins[i]Truedecreasing
bins[i-1] < x <= bins[i]If values in x are beyond the bounds of bins, 0 or
len(bins)is returned as appropriate.- Parameters
- xarray_like
Input array to be binned.
- binsarray_like
Array of bins. It has to be 1-dimensional and monotonic.
- rightbool, optional
Indicating whether the intervals include the right or the left bin edge. Default behavior is (right==False) indicating that the interval does not include the right edge. The left bin end is open in this case, i.e., bins[i-1] <= x < bins[i] is the default behavior for monotonically increasing bins.
- Returns
- indicesndarray of ints
Output array of indices, of same shape as x.
参考
注釈
If values in x are such that they fall outside the bin range, attempting to index bins with the indices that
digitize()returns will result in an IndexError.For monotonically _increasing_ bins, the following are equivalent:
vp.digitize(x, bins, right=True)
Note that as the order of the arguments are reversed, the side must be too.
制限事項
This function is the wrapper function to utilize
numpy.digitize(). Calculations during this function perform on only Vector Host(Linux/x86).Examples
>>> import nlcpy as vp >>> x = vp.array([0.2, 6.4, 3.0, 1.6]) >>> bins = vp.array([0.0, 1.0, 2.5, 4.0, 10.0]) >>> inds = vp.digitize(x, bins) >>> inds array([1, 4, 3, 2]) >>> for n in range(x.size): ... print(bins[inds[n]-1], "<=", x[n], "<", bins[inds[n]]) ... 0.0 <= 0.2 < 1.0 4.0 <= 6.4 < 10.0 2.5 <= 3.0 < 4.0 1.0 <= 1.6 < 2.5 >>> x = vp.array([1.2, 10.0, 12.4, 15.5, 20.]) >>> bins = vp.array([0, 5, 10, 15, 20]) >>> vp.digitize(x,bins,right=True) array([1, 2, 3, 4, 4]) >>> vp.digitize(x,bins,right=False) array([1, 3, 3, 4, 5])