本文整理汇总了Python中brian2.groups.neurongroup.NeuronGroup.v['v<3*volt']方法的典型用法代码示例。如果您正苦于以下问题:Python NeuronGroup.v['v<3*volt']方法的具体用法?Python NeuronGroup.v['v<3*volt']怎么用?Python NeuronGroup.v['v<3*volt']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brian2.groups.neurongroup.NeuronGroup
的用法示例。
在下文中一共展示了NeuronGroup.v['v<3*volt']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_state_variable_access_strings
# 需要导入模块: from brian2.groups.neurongroup import NeuronGroup [as 别名]
# 或者: from brian2.groups.neurongroup.NeuronGroup import v['v<3*volt'] [as 别名]
def test_state_variable_access_strings():
for codeobj_class in codeobj_classes:
G = NeuronGroup(10, 'v:volt', codeobj_class=codeobj_class)
G.v = np.arange(10) * volt
# Indexing with strings
assert G.v['i==2'] == G.v[2]
assert G.v_['i==2'] == G.v_[2]
assert_equal(G.v['v >= 3*volt'], G.v[3:])
assert_equal(G.v_['v >= 3*volt'], G.v_[3:])
# Should also check for units
assert_raises(DimensionMismatchError, lambda: G.v['v >= 3'])
assert_raises(DimensionMismatchError, lambda: G.v['v >= 3*second'])
# Setting with strings
# --------------------
# String value referring to i
G.v = '2*i*volt'
assert_equal(G.v[:], 2*np.arange(10)*volt)
# String value referring to i
G.v[:5] = '3*i*volt'
assert_equal(G.v[:],
np.array([0, 3, 6, 9, 12, 10, 12, 14, 16, 18])*volt)
G.v = np.arange(10) * volt
# String value referring to a state variable
G.v = '2*v'
assert_equal(G.v[:], 2*np.arange(10)*volt)
G.v[:5] = '2*v'
assert_equal(G.v[:],
np.array([0, 4, 8, 12, 16, 10, 12, 14, 16, 18])*volt)
G.v = np.arange(10) * volt
# String value referring to state variables, i, and an external variable
ext = 5*volt
G.v = 'v + ext + (N + i)*volt'
assert_equal(G.v[:], 2*np.arange(10)*volt + 15*volt)
G.v = np.arange(10) * volt
G.v[:5] = 'v + ext + (N + i)*volt'
assert_equal(G.v[:],
np.array([15, 17, 19, 21, 23, 5, 6, 7, 8, 9])*volt)
G.v = 'v + randn()*volt' # only check that it doesn't raise an error
G.v[:5] = 'v + randn()*volt' # only check that it doesn't raise an error
G.v = np.arange(10) * volt
# String index using a random number
G.v['rand() <= 1'] = 0*mV
assert_equal(G.v[:], np.zeros(10)*volt)
G.v = np.arange(10) * volt
# String index referring to i and setting to a scalar value
G.v['i>=5'] = 0*mV
assert_equal(G.v[:], np.array([0, 1, 2, 3, 4, 0, 0, 0, 0, 0])*volt)
# String index referring to a state variable
G.v['v<3*volt'] = 0*mV
assert_equal(G.v[:], np.array([0, 0, 0, 3, 4, 0, 0, 0, 0, 0])*volt)
# String index referring to state variables, i, and an external variable
ext = 2*volt
G.v['v>=ext and i==(N-6)'] = 0*mV
assert_equal(G.v[:], np.array([0, 0, 0, 3, 0, 0, 0, 0, 0, 0])*volt)
G.v = np.arange(10) * volt
# Strings for both condition and values
G.v['i>=5'] = 'v*2'
assert_equal(G.v[:], np.array([0, 1, 2, 3, 4, 10, 12, 14, 16, 18])*volt)
G.v['v>=5*volt'] = 'i*volt'
assert_equal(G.v[:], np.arange(10)*volt)
示例2: test_state_variable_access_strings
# 需要导入模块: from brian2.groups.neurongroup import NeuronGroup [as 别名]
# 或者: from brian2.groups.neurongroup.NeuronGroup import v['v<3*volt'] [as 别名]
def test_state_variable_access_strings():
G = NeuronGroup(10, '''v : volt
dv_ref/dt = -v_ref/(10*ms) : 1 (unless refractory)''',
threshold='v_ref>1', reset='v_ref=1', refractory=1*ms)
G.v = np.arange(10) * volt
# Indexing with strings
assert G.v['i==2'] == G.v[2]
assert G.v_['i==2'] == G.v_[2]
assert_equal(G.v['v >= 3*volt'], G.v[3:])
assert_equal(G.v_['v >= 3*volt'], G.v_[3:])
# Should also check for units
assert_raises(DimensionMismatchError, lambda: G.v['v >= 3'])
assert_raises(DimensionMismatchError, lambda: G.v['v >= 3*second'])
# Setting with strings
# --------------------
# String value referring to i
G.v = '2*i*volt'
assert_equal(G.v[:], 2*np.arange(10)*volt)
# String value referring to i
G.v[:5] = '3*i*volt'
assert_equal(G.v[:],
np.array([0, 3, 6, 9, 12, 10, 12, 14, 16, 18])*volt)
G.v = np.arange(10) * volt
# Conditional write variable
G.v_ref = '2*i'
assert_equal(G.v_ref[:], 2*np.arange(10))
# String value referring to a state variable
G.v = '2*v'
assert_equal(G.v[:], 2*np.arange(10)*volt)
G.v[:5] = '2*v'
assert_equal(G.v[:],
np.array([0, 4, 8, 12, 16, 10, 12, 14, 16, 18])*volt)
G.v = np.arange(10) * volt
# String value referring to state variables, i, and an external variable
ext = 5*volt
G.v = 'v + ext + (N + i)*volt'
assert_equal(G.v[:], 2*np.arange(10)*volt + 15*volt)
G.v = np.arange(10) * volt
G.v[:5] = 'v + ext + (N + i)*volt'
assert_equal(G.v[:],
np.array([15, 17, 19, 21, 23, 5, 6, 7, 8, 9])*volt)
G.v = 'v + randn()*volt' # only check that it doesn't raise an error
G.v[:5] = 'v + randn()*volt' # only check that it doesn't raise an error
G.v = np.arange(10) * volt
# String index using a random number
G.v['rand() <= 1'] = 0*mV
assert_equal(G.v[:], np.zeros(10)*volt)
G.v = np.arange(10) * volt
# String index referring to i and setting to a scalar value
G.v['i>=5'] = 0*mV
assert_equal(G.v[:], np.array([0, 1, 2, 3, 4, 0, 0, 0, 0, 0])*volt)
# String index referring to a state variable
G.v['v<3*volt'] = 0*mV
assert_equal(G.v[:], np.array([0, 0, 0, 3, 4, 0, 0, 0, 0, 0])*volt)
# String index referring to state variables, i, and an external variable
ext = 2*volt
G.v['v>=ext and i==(N-6)'] = 0*mV
assert_equal(G.v[:], np.array([0, 0, 0, 3, 0, 0, 0, 0, 0, 0])*volt)
G.v = np.arange(10) * volt
# Strings for both condition and values
G.v['i>=5'] = 'v*2'
assert_equal(G.v[:], np.array([0, 1, 2, 3, 4, 10, 12, 14, 16, 18])*volt)
G.v['v>=5*volt'] = 'i*volt'
assert_equal(G.v[:], np.arange(10)*volt)
G.v['i<=5'] = '(100 + rand())*volt'
assert_equal(G.v[6:], np.arange(4)*volt + 6*volt) # unchanged
assert all(G.v[:6] >= 100*volt)
assert all(G.v[:6] <= 101*volt)
assert np.var(G.v_[:6]) > 0