本文整理匯總了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