spiketools.spatial.occupancy.compute_bin_counts_assgn¶
- spiketools.spatial.occupancy.compute_bin_counts_assgn(bins, xbins, ybins=None, occupancy=None)[source]¶
Compute number of counts per bin, from bin assignments.
- Parameters:
- binsint or list of [int, int]
The bin definition for dividing up the space. If 1d, can be integer. If 2d should be a list, defined as [number of x_bins, number of y_bins].
- xbins1d array
Bin assignments for the x-dimension.
- ybins1d array, optional
Bin assignments for the y-dimension.
- occupancy1d or 2d array, optional
Occupancy across the spatial bins. If provided, used to normalize bin counts.
- Returns:
- bin_counts1d or 2d array
Amount of counts in each bin. For 2d, has shape [n_y_bins, n_x_bins] (see notes).
Notes
For the 2d case, note that while the inputs to this function list the x-axis first, the output of this function, being a 2d array, follows the numpy convention in which columns (y-axis) are on the 0th dimension, and rows (x-axis) are on the 1th dimension.
Examples
Compute the bin counts per bin for 1d data, given precomputed x bin assignments:
>>> bins = 3 >>> xbins = [0, 2, 1, 0, 1] >>> compute_bin_counts_assgn(bins, xbins) array([2, 2, 1])
Compute the bin counts for 1d data, given precomputed x & y bin assignments:
>>> bins = [2, 2] >>> xbins = [0, 0, 0, 1] >>> ybins = [0, 0, 1, 1] >>> compute_bin_counts_assgn(bins, xbins, ybins) array([[2., 0.], [1., 1.]])