本文整理匯總了Python中theano.foldr方法的典型用法代碼示例。如果您正苦於以下問題:Python theano.foldr方法的具體用法?Python theano.foldr怎麽用?Python theano.foldr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類theano
的用法示例。
在下文中一共展示了theano.foldr方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: foldr
# 需要導入模塊: import theano [as 別名]
# 或者: from theano import foldr [as 別名]
def foldr(fn, elems, initializer=None, name=None):
'''Reduce elems using fn to combine them from right to left.
# Arguments
fn: Callable that will be called upon each element in elems and an
accumulator, for instance lambda acc, x: acc + x
elems: tensor
initializer: The first value used (elems[-1] in case of None)
name: A string name for the foldr node in the graph
# Returns
Same type and shape as initializer
'''
if initializer is None:
initializer = elems[-1]
elems = elems[:-1]
# We need to change the order of the arguments because theano accepts x as
# first parameter and accumulator as second
fn2 = lambda x, acc: fn(acc, x)
return theano.foldr(fn2, elems, initializer, name=name)[0]
示例2: foldr
# 需要導入模塊: import theano [as 別名]
# 或者: from theano import foldr [as 別名]
def foldr(fn, elems, initializer=None, name=None):
"""Reduce elems using fn to combine them from right to left.
# Arguments
fn: Callable that will be called upon each element in elems and an
accumulator, for instance lambda acc, x: acc + x
elems: tensor
initializer: The first value used (elems[-1] in case of None)
name: A string name for the foldr node in the graph
# Returns
Same type and shape as initializer
"""
if initializer is None:
initializer = elems[-1]
elems = elems[:-1]
# We need to change the order of the arguments because theano accepts x as
# first parameter and accumulator as second
return theano.foldr(lambda x, acc: fn(acc, x),
elems, initializer, name=name)[0]
示例3: foldr
# 需要導入模塊: import theano [as 別名]
# 或者: from theano import foldr [as 別名]
def foldr(fn, elems, initializer=None, name=None):
"""Reduce elems using fn to combine them from right to left.
# Arguments
fn: Callable that will be called upon each element in elems and an
accumulator, for instance lambda acc, x: acc + x
elems: tensor
initializer: The first value used (elems[-1] in case of None)
name: A string name for the foldr node in the graph
# Returns
Same type and shape as initializer
"""
if initializer is None:
initializer = elems[-1]
elems = elems[:-1]
# We need to change the order of the arguments because theano accepts x as
# first parameter and accumulator as second
fn2 = lambda x, acc: fn(acc, x)
return theano.foldr(fn2, elems, initializer, name=name)[0]