digitize(a, bins, right=False)
This docstring was copied from numpy.digitize.
Some inconsistencies with the Dask version may exist.
========= ============= ============================ :None:None:`right`
order of bins returned index i
satisfies ========= ============= ============================ False
increasing bins[i-1] <= x < bins[i]
True
increasing bins[i-1] < x <= bins[i]
False
decreasing bins[i-1] > x >= bins[i]
True
decreasing bins[i-1] >= x > bins[i]
========= ============= ============================
If values in x
are beyond the bounds of :None:None:`bins`
, 0 or len(bins)
is returned as appropriate.
If values in x
are such that they fall outside the bin range, attempting to index :None:None:`bins`
with the indices that digitize
returns will result in an IndexError.
:None:None:`np.digitize`
is implemented in terms of :None:None:`np.searchsorted`
. This means that a binary search is used to bin the values, which scales much better for larger number of bins than the previous linear search. It also removes the requirement for the input array to be 1-dimensional.
For monotonically _increasing_ :None:None:`bins`
, the following are equivalent:
np.digitize(x, bins, right=True) np.searchsorted(bins, x, side='left')
Note that as the order of the arguments are reversed, the side must be too. The searchsorted
call is marginally faster, as it does not do any monotonicity checks. Perhaps more importantly, it supports all dtypes.
Input array to be binned. Prior to NumPy 1.10.0, this array had to be 1-dimensional, but can now have any shape.
Array of bins. It has to be 1-dimensional and monotonic.
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.
If :None:None:`bins`
is not monotonic.
If the type of the input is complex.
Return the indices of the bins to which each value in input array belongs.
>>> x = np.array([0.2, 6.4, 3.0, 1.6]) # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... bins = np.array([0.0, 1.0, 2.5, 4.0, 10.0]) # doctest: +SKIP
... inds = np.digitize(x, bins) # doctest: +SKIP
... inds # doctest: +SKIP array([1, 4, 3, 2])
>>> for n in range(x.size): # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... 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 = np.array([1.2, 10.0, 12.4, 15.5, 20.]) # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... bins = np.array([0, 5, 10, 15, 20]) # doctest: +SKIP
... np.digitize(x,bins,right=True) # doctest: +SKIP array([1, 2, 3, 4, 4])
>>> np.digitize(x,bins,right=False) # doctest: +SKIP array([1, 3, 3, 4, 5])See :
The following pages refer to to this document either explicitly or contain code examples using this.
dask.array.routines.bincount
dask.array.routines.digitize
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them