calc_repeats function

(Shortest import: from brian2.utils.arrays import calc_repeats)


Calculates offsets corresponding to an array, where repeated values are subsequently numbered, i.e. if there n identical values, the returned array will have values from 0 to n-1 at their positions. The code is complex because tricks are needed for vectorisation.

This function is used in the Python SpikeQueue to calculate the offset array for the insertion of spikes with their respective delays into the queue and in the numpy code for synapse creation to calculate how many synapses for each source-target pair exist.


>>> import numpy as np
>>> print(calc_repeats(np.array([7, 5, 7, 3, 7, 5])))
[0 0 1 0 2 1]