Hướng dẫn dùng numpy digitize python

numpy.digitize[x, bins, right=False][source]#

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] bins[i]

If values in x are beyond the bounds of bins, 0 or len[bins] is returned as appropriate.

Parametersxarray_like

Input array to be binned. Prior to NumPy 1.10.0, this array had to be 1-dimensional, but can now have any shape.

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 = np.array[[0.2, 6.4, 3.0, 1.6]] >>> bins = np.array[[0.0, 1.0, 2.5, 4.0, 10.0]] >>> inds = np.digitize[x, bins] >>> inds array[[1, 4, 3, 2]] >>> for n in range[x.size]: ... print[bins[inds[n]-1], "

Chủ Đề