calculate_entry_multiplicity¶
- halotools.utils.calculate_entry_multiplicity(sorted_repeated_hostids, unique_possible_hostids, testing_mode=False)[source]¶
Given an array of possible hostids, and a sorted array of (possibly repeated) hostids, return the number of appearances of each hostid.
This function can serve as the kernel, for example, for the calculation of the number of subhalos in each host halo.
- Parameters:
- sorted_repeated_hostidsarray
Length-num_entries integer array storing a collection of hostids.
The entries of
sorted_repeated_hostidsmay be repeated, but must be in ascending order. Each entry ofsorted_repeated_hostidsmust appear in theunique_possible_hostids.For halo analysis applications, this would be the
halo_hostidcolumn of some set of subhalos.- unique_possible_hostidsarray
Length-num_hostids integer array storing the set of all available values for hostid.
All entries must be unique. An entry of
unique_possible_hostidsneed not necessarily appear insorted_repeated_hostids. Theunique_possible_hostidsarray can be sorted in any order.For halo analysis applications, this would be the
halo_idcolumn of the complete set of host halos.- testing_modebool, optional
Boolean specifying whether input arrays will be tested to see if they satisfy the assumptions required by the algorithm. Setting
testing_modeto True is useful for unit-testing purposes, while setting it to False improves performance. Default is False. If this function raises an unexpected exception, try settingtesting_modeto True to identify which specific assumption about the inputs is not being met.
- Returns:
- entry_multiplicityarray
Length-num_hostids integer array storing the number of times each entry of
unique_possible_hostidsappears insorted_repeated_hostids.
Examples
>>> sorted_repeated_hostids = np.array((1, 1, 2, 2, 2, 4, 5, 6, 6)) >>> unique_possible_hostids = np.arange(7) >>> entry_multiplicity = calculate_entry_multiplicity(sorted_repeated_hostids, unique_possible_hostids) >>> assert np.all(entry_multiplicity == (0, 2, 3, 0, 1, 1, 2))