Variable#

class brainpy.math.Variable(value_or_size, dtype=None, batch_axis=None, *, axis_names=None, ready_to_trace=None)[source]#

The pointer to specify the dynamical variable.

Initializing an instance of Variable by two ways:

>>> import brainpy.math as bm
>>> # 1. init a Variable by the concreate data
>>> v1 = bm.Variable(bm.zeros(10))
>>> # 2. init a Variable by the data shape
>>> v2 = bm.Variable(10)

Note that when initializing a Variable by the data shape, all values in this Variable will be initialized as zeros.

Parameters:
  • value_or_size (Any) – Shape, Array, int. The value or the size of the value.

  • dtype (Optional[type]) – Any. The type of the data.

  • batch_axis (Optional[int]) – optional, int. The batch axis.

  • axis_names (Optional[Sequence[str]]) – sequence of str. The name for each axis.

clone()[source]#

Clone the variable.

Return type:

Variable

tree_flatten()[source]#

Flattens this variable.

Returns:

A pair where the first element is a list of leaf values and the second element is a treedef representing the structure of the flattened tree.

classmethod tree_unflatten(aux_data, flat_contents)[source]#

Reconstructs a variable from the aux_data and the leaves.

Parameters:
  • aux_data

  • flat_contents

Returns:

The variable.