to_start_stop function

(Shortest import: from brian2.groups.neurongroup import to_start_stop)

brian2.groups.neurongroup.to_start_stop(item, N)[source]

Helper function to transform a single number, a slice or an array of contiguous indices to a start and stop value. This is used to allow for some flexibility in the syntax of specifying subgroups in NeuronGroup and SpatialNeuron.

Parameters

item : slice, int or sequence

The slice, index, or sequence of indices to use. Note that a sequence of indices has to be a sorted ascending sequence of subsequent integers.

N : int

The total number of elements in the group.

Returns

start : int

The start value of the slice.

stop : int

The stop value of the slice.

Examples

>>> from brian2.groups.neurongroup import to_start_stop
>>> to_start_stop(slice(3, 6), 10)
(3, 6)
>>> to_start_stop(slice(3, None), 10)
(3, 10)
>>> to_start_stop(5, 10)
(5, 6)
>>> to_start_stop([3, 4, 5], 10)
(3, 6)
>>> to_start_stop([3, 5, 7], 10)
Traceback (most recent call last):
    ...
IndexError: Subgroups can only be constructed using contiguous indices.