本文整理汇总了Python中multiprocessing.Array.append方法的典型用法代码示例。如果您正苦于以下问题:Python Array.append方法的具体用法?Python Array.append怎么用?Python Array.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Array
的用法示例。
在下文中一共展示了Array.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from multiprocessing import Array [as 别名]
# 或者: from multiprocessing.Array import append [as 别名]
class SynapseEnvironment:
def __init__(self, noise=0.0):
def beta(maximum, rate=1.0):
return betav(maximum, noise=noise, rate=rate)
self.beta = beta
self.prev_concentrations = []
self.next_concentrations = []
def initialize(self):
# Create thread safe arrays.
self.prev_concentrations = Array('d', self.prev_concentrations, lock=False)
self.next_concentrations = Array('d', self.next_concentrations, lock=False)
self.dirty = Value('b', True, lock=False)
def register(self, baseline_concentration):
pool_id = len(self.prev_concentrations)
self.prev_concentrations.append(baseline_concentration)
self.next_concentrations.append(baseline_concentration)
return pool_id
def get_concentration(self, pool_id):
try: self.dirty
except: self.initialize()
return self.prev_concentrations[pool_id]
def set_concentration(self, pool_id, new_concentration):
try: self.dirty.value = True
except: self.initialize()
self.next_concentrations[pool_id] = new_concentration
def add_concentration(self, pool_id, molecules):
try: self.dirty.value = True
except: self.initialize()
self.next_concentrations[pool_id] += molecules
def remove_concentration(self, pool_id, molecules):
try: self.dirty.value = True
except: self.initialize()
self.next_concentrations[pool_id] -= molecules
self.next_concentrations[pool_id] = \
max(0.0, self.next_concentrations[pool_id])
def step(self):
"""
Cycles the environment.
Returns whether the environment is stable (not dirty, no changes)
"""
try: self.dirty
except: self.initialize()
if self.dirty.value:
self.dirty.value = False
for i in xrange(len(self.prev_concentrations)):
self.prev_concentrations[i]=self.next_concentrations[i]
return False
else: return True