calculate_last_idx_unique_array_vals

halotools.utils.calculate_last_idx_unique_array_vals(sorted_array, testing_mode=False)[source]

Given an integer array with possibly repeated entries in ascending order, return the indices of the last appearance of each unique value.

Parameters:
sorted_arrayarray

Integer array of host halo IDs, sorted in ascending order

testing_modebool, 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 unit-testing purposes, while setting it to False improves performance. Default is False. If this function raises an unexpected exception, try setting testing_mode to True to identify which specific assumption about the inputs is not being met.

Returns:
idx_unique_array_valsarray

Integer array storing the indices of the last appearance of each unique entry in sorted_array

Notes

By construction, the first element of calculate_first_idx_unique_array_vals will always be len(sorted_array)-1.

Examples

>>> sorted_array = np.array((0, 0, 1, 1, 4, 8, 8, 10))
>>> result = calculate_last_idx_unique_array_vals(sorted_array)
>>> assert np.all(result == (1, 3, 4, 6, 7))