sum_in_bins¶

halotools.utils.
sum_in_bins
(arr, sorted_bin_numbers, testing_mode=False)[source] [edit on github]¶ Given an array of values
arr
and another equallength arraysorted_bin_numbers
storing how these values have been binned into Nbins, calculate the sum of the values in each bin.Parameters: arr : array
Array of length Nvals storing the quantity to be summed in the bins defined by
sorted_bin_numbers
.sorted_bin_numbers : array
Integer array of length Nvals storing the bin numbers of each entry of the input
arr
, e.g., the result of np.digitize(arr, bins). Thesorted_bin_numbers
array may have repeated entries but must be in ascending order. That is, the subhalos whose property is stored in arrayarr
will be presumed to be pregrouped according to, for example, host halo mass, with lowest halo masses first, and higher halo masses at higher indices, in monotonic fashion.testing_mode : bool, optional
Boolean specifying whether input arrays will be tested to see if they satisfy the assumptions required by the algorithm. Setting
testing_mode
to True is useful for unittesting purposes, while setting it to False improves performance. Default is False.Returns: binned_sum : array
Array of lengthNbins storing the sum of
arr
values within the bins defined bysorted_bin_numbers
.Examples
>>> Nvals = 5 >>> arr = np.arange(Nvals) >>> sorted_bin_numbers = np.array((1, 2, 2, 6, 7)) >>> result = sum_in_bins(arr, sorted_bin_numbers)