本文整理汇总了Python中tensorflow.python.ops.functional_ops.foldr函数的典型用法代码示例。如果您正苦于以下问题:Python foldr函数的具体用法?Python foldr怎么用?Python foldr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了foldr函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testFoldr_Simple
def testFoldr_Simple(self):
elems = constant_op.constant([1, 2, 3, 4, 5, 6], name="data")
r = functional_ops.foldr(
lambda a, x: math_ops.multiply(math_ops.add(a, x), 2),
elems)
self.assertAllEqual(450, self.evaluate(r))
r = functional_ops.foldr(
lambda a, x: math_ops.multiply(math_ops.add(a, x), 2),
elems,
initializer=10)
self.assertAllEqual(1282, self.evaluate(r))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:13,代码来源:functional_ops_test.py
示例2: testFoldr_Simple
def testFoldr_Simple(self):
with self.test_session():
elems = constant_op.constant([1, 2, 3, 4, 5, 6], name="data")
r = functional_ops.foldr(lambda a, x: math_ops.mul(math_ops.add(a, x), 2),
elems)
self.assertAllEqual(450, r.eval())
r = functional_ops.foldr(
lambda a, x: math_ops.mul(math_ops.add(a, x), 2),
elems,
initializer=10)
self.assertAllEqual(1282, r.eval())
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:13,代码来源:functional_ops_test.py
示例3: testFoldr_MultiInputSingleOutput
def testFoldr_MultiInputSingleOutput(self):
with self.test_session():
elems = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
initializer = np.array(1.0)
r = functional_ops.foldr(lambda a, x: a + x[0] + x[1], (elems, -elems),
initializer)
self.assertAllEqual(1, self.evaluate(r))
开发者ID:Jackiefan,项目名称:tensorflow,代码行数:7,代码来源:functional_ops_test.py
示例4: testFoldr_SingleInputMultiOutput
def testFoldr_SingleInputMultiOutput(self):
elems = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
initializer = np.array([1, -1.0])
r = functional_ops.foldr(lambda a, x: a + x, elems, initializer)
r_value = self.evaluate(r)
self.assertAllEqual(22, r_value[0])
self.assertAllEqual(20, r_value[1])
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:8,代码来源:functional_ops_test.py
示例5: testFoldr_Scoped
def testFoldr_Scoped(self):
with self.cached_session() as sess:
with variable_scope.variable_scope("root") as varscope:
elems = constant_op.constant([1, 2, 3, 4, 5, 6], name="data")
r = functional_ops.foldr(simple_scoped_fn, elems)
# Check that we have the one variable we asked for here.
self.assertEqual(len(variables.trainable_variables()), 1)
self.assertEqual(variables.trainable_variables()[0].name,
"root/body/two:0")
sess.run([variables.global_variables_initializer()])
self.assertAllEqual(450, self.evaluate(r))
# Now let's reuse our single variable.
varscope.reuse_variables()
r = functional_ops.foldr(simple_scoped_fn, elems, initializer=10)
self.assertEqual(len(variables.trainable_variables()), 1)
self.assertAllEqual(1282, self.evaluate(r))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:18,代码来源:functional_ops_test.py
示例6: testFold_Grad
def testFold_Grad(self):
with self.cached_session():
elems = constant_op.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], name="data")
v = constant_op.constant(2.0, name="v")
r = functional_ops.foldl(
lambda a, x: math_ops.multiply(a, x), elems, initializer=v)
r = gradients_impl.gradients(r, v)[0]
self.assertAllEqual(720.0, self.evaluate(r))
r = functional_ops.foldr(
lambda a, x: math_ops.multiply(a, x), elems, initializer=v)
r = gradients_impl.gradients(r, v)[0]
self.assertAllEqual(720.0, self.evaluate(r))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:13,代码来源:functional_ops_test.py
注:本文中的tensorflow.python.ops.functional_ops.foldr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论