VariableView class

(Shortest import: from brian2.core.variables import VariableView)

class brian2.core.variables.VariableView(name, variable, group, unit=None)[source]

Bases: object

A view on a variable that allows to treat it as an numpy array while allowing special indexing (e.g. with strings) in the context of a Group.

Parameters:

name : str

The name of the variable (not necessarily the same as variable.name).

variable : Variable

The variable description.

group : Group

The group through which the variable is accessed (not necessarily the same as variable.owner).

unit : Unit, optional

The unit to be used for the variable, should be None when a variable

is accessed without units (e.g. when accessing G.var_).

Attributes

dim The dimensions of this variable.

Methods

get_item(item[, level, namespace]) Get the value of this variable.
set_item(item, value[, level, namespace]) Set this variable.

Details

dim

The dimensions of this variable.

get_item(item, level=0, namespace=None)[source]

Get the value of this variable. Called by __getitem__.

Parameters:

item : slice, ndarray or string

The index for the setting operation

level : int, optional

How much farther to go up in the stack to find the implicit namespace (if used, see run_namespace).

namespace : dict-like, optional

An additional namespace that is used for variable lookup (if not defined, the implicit namespace of local variables is used).

get_subexpression_with_index_array(*args, **kwds)
get_with_expression(*args, **kwds)

Gets a variable using a string expression. Is called by VariableView.get_item for statements such as print G.v['g_syn > 0'].

Parameters:

code : str

An expression that states a condition for elements that should be selected. Can contain references to indices, such as i or j and to state variables. For example: 'i>3 and v>0*mV'.

level : int, optional

How much farther to go up in the stack to find the implicit namespace (if used, see run_namespace).

run_namespace : dict-like, optional

An additional namespace that is used for variable lookup (if not defined, the implicit namespace of local variables is used).

get_with_index_array(*args, **kwds)
set_item(item, value, level=0, namespace=None)[source]

Set this variable. This function is called by __setitem__ but there is also a situation where it should be called directly: if the context for string-based expressions is higher up in the stack, this function allows to set the level argument accordingly.

Parameters:

item : slice, ndarray or string

The index for the setting operation

value : Quantity, ndarray or number

The value for the setting operation

level : int, optional

How much farther to go up in the stack to find the implicit namespace (if used, see run_namespace).

namespace : dict-like, optional

An additional namespace that is used for variable lookup (if not defined, the implicit namespace of local variables is used).

set_with_expression(*args, **kwds)

Sets a variable using a string expression. Is called by VariableView.set_item for statements such as S.var[:, :] = 'exp(-abs(i-j)/space_constant)*nS'

Parameters:

item : ndarray

The indices for the variable (in the context of this group).

code : str

The code that should be executed to set the variable values. Can contain references to indices, such as i or j

check_units : bool, optional

Whether to check the units of the expression.

level : int, optional

How much farther to go up in the stack to find the implicit namespace (if used, see run_namespace).

run_namespace : dict-like, optional

An additional namespace that is used for variable lookup (if not defined, the implicit namespace of local variables is used).

set_with_expression_conditional(*args, **kwds)

Sets a variable using a string expression and string condition. Is called by VariableView.set_item for statements such as S.var['i!=j'] = 'exp(-abs(i-j)/space_constant)*nS'

Parameters:

cond : str

The string condition for which the variables should be set.

code : str

The code that should be executed to set the variable values.

check_units : bool, optional

Whether to check the units of the expression.

level : int, optional

How much farther to go up in the stack to find the implicit namespace (if used, see run_namespace).

run_namespace : dict-like, optional

An additional namespace that is used for variable lookup (if not defined, the implicit namespace of local variables is used).

set_with_index_array(*args, **kwds)