# LazyArange class¶

(Shortest import: from brian2.codegen.runtime.numpy_rt.numpy_rt import LazyArange)

class brian2.codegen.runtime.numpy_rt.numpy_rt.LazyArange(stop, start=0, indices=None)[source]

A class that can be used as a arange replacement (with an implied step size of 1) but does not actually create an array of values until necessary. It is somewhat similar to the range() function in Python 3, but does not use a generator. It is tailored to a special use case, the _vectorisation_idx variable in numpy templates, and not meant for general use. The _vectorisation_idx is used for stateless function calls such as rand() and for the numpy codegen target determines the number of values produced by such a call. This will often be the number of neurons or synapses, and this class avoids creating a new array of that size at every code object call when all that is needed is the length of the array.

Examples

>>> from brian2.codegen.runtime.numpy_rt.numpy_rt import LazyArange
>>> ar = LazyArange(10)
>>> len(ar)
10
>>> len(ar[:5])
5
>>> type(ar[:5])
<class 'brian2.codegen.runtime.numpy_rt.numpy_rt.LazyArange'>
>>> ar[5]
5
>>> for value in ar[3:7]:
...     print(value)
...
3
4
5
6
>>> len(ar[np.array([1, 2, 3])])
3