halotools.utils.calculate_first_idx_unique_array_vals(sorted_array, testing_mode=False)[source] [edit on github]

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

sorted_array : array

Integer array of host halo IDs, sorted in ascending order

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 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.

idx_unique_array_vals : array

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


By construction, the first element of calculate_first_idx_unique_array_vals will always be zero.


>>> sorted_array = np.array((0, 0, 1, 1, 4, 8, 8, 10))
>>> result = calculate_first_idx_unique_array_vals(sorted_array)
>>> assert np.all(result == (0, 2, 4, 5, 7))