spacepy.toolbox.arraybin

spacepy.toolbox.arraybin(array, bins)[source]

Split a sequence into subsequences based on value.

Given a sequence of values and a sequence of values representing the division between bins, return the indices grouped by bin.

Parameters
arrayarray_like

the input sequence to slice, must be sorted in ascending order

binsarray_like
dividing lines between bins. Number of bins is len(bins)+1,

value that exactly equal a dividing value are assigned to the higher bin

Returns
outlist

indices for each bin (list of lists)

Examples

>>> import spacepy.toolbox as tb
>>> tb.arraybin(range(10), [4.2])
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]