spiketools.utils.data.assign_data_to_bins¶
- spiketools.utils.data.assign_data_to_bins(data, edges, check_range=True, include_edge=True)[source]¶
Assign data values to data bins, based on given edges.
- Parameters:
- data1d array
Data values to bin.
- edges1d array
Edge definitions for the binning.
- check_rangebool, optional, default: True
Whether to check if the given edges fully cover the given data. If True, runs a check that raises a warning if any data values exceed edge ranges.
- include_edgebool, optional, default: True
Whether to include data values on the edge into the bin.
- Returns:
- assignments1d array
Bin assignments per data value.
Examples
Assign data values into bins given the bin edges:
>>> data = np.array([0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 1.1, 1.2, 1.3, 1.4]) >>> edges = np.array([0, 0.5, 1, 1.5]) >>> assign_data_to_bins(data, edges) array([0, 0, 0, 1, 1, 1, 2, 2, 2, 2])