VariableView class¶
(Shortest import: from brian2.core.variables import VariableView)
- class brian2.core.variables.VariableView(name, variable, group, dimensions=None)[source]¶
Bases:
objectA 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 :
VariableThe variable description.
group :
GroupThe group through which the variable is accessed (not necessarily the same as
variable.owner).dimensions :
Dimension, optionalThe physical dimensions to be used for the variable, should be
Nonewhen a variable is accessed without units (e.g. when accessingG.var_).
Attributes
The
Unitof this variableMethods
get_item(item[, level, namespace])Get the value of this variable.
get_subexpression_with_index_array(item, ...)get_with_expression(code, run_namespace)Gets a variable using a string expression.
get_with_index_array(item)set_item(item, value[, level, namespace])Set this variable.
set_with_expression(item, code, run_namespace)Sets a variable using a string expression.
set_with_expression_conditional(cond, code, ...)Sets a variable using a string expression and string condition.
set_with_index_array(item, value, check_units)Details
- dtype¶
- ndim¶
- shape¶
- get_item(item, level=0, namespace=None)[source]¶
Get the value of this variable. Called by
__getitem__.- Parameters:
item : slice,
ndarrayor stringThe 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_with_expression(code, run_namespace)[source]¶
Gets a variable using a string expression. Is called by
VariableView.get_itemfor statements such asprint(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
iorjand to state variables. For example:'i>3 and v>0*mV'.run_namespace : dict-like
An additional namespace that is used for variable lookup (either an explicitly defined namespace or one taken from the local context).
- 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 thelevelargument accordingly.- Parameters:
item : slice,
ndarrayor stringThe index for the setting operation
value :
Quantity,ndarrayor numberThe 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(item, code, run_namespace, check_units=True)[source]¶
Sets a variable using a string expression. Is called by
VariableView.set_itemfor statements such asS.var[:, :] = 'exp(-abs(i-j)/space_constant)*nS'- Parameters:
item :
ndarrayThe 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
iorjrun_namespace : dict-like, optional
An additional namespace that is used for variable lookup (if not defined, the implicit namespace of local variables is used).
check_units : bool, optional
Whether to check the units of the expression.
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(cond, code, run_namespace, check_units=True)[source]¶
Sets a variable using a string expression and string condition. Is called by
VariableView.set_itemfor statements such asS.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.
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).
check_units : bool, optional
Whether to check the units of the expression.