|View source on GitHub|
foldr on the list of tensors unpacked from
elems on dimension 0. (deprecated argument values)
tf.foldr( fn, elems, initializer=None, parallel_iterations=10, back_prop=True, swap_memory=False, name=None )
This foldr operator repeatedly applies the callable
fn to a sequence of elements from last to first. The elements are made of the tensors unpacked from
elems. The callable fn takes two tensors as arguments. The first argument is the accumulated value computed from the preceding invocation of fn, and the second is the value at the current position of
initializer is None,
elems must contain at least one element, and its first element is used as the initializer.
elems is unpacked into
values, a list of tensors. The shape of the result tensor is
This method also allows multi-arity
elems and output of
elems is a (possibly nested) list or tuple of tensors, then each of these tensors must have a matching first (unpack) dimension. The signature of
fn may match the structure of
elems. That is, if
(t1, [t2, t3, [t4, t5]]), then an appropriate signature for
fn = lambda (t1, [t2, t3, [t4, t5]]):.
| ||The callable to be performed.|
| || A tensor or (possibly nested) sequence of tensors, each of which will be unpacked along their first dimension. The nested sequence of the resulting slices will be the first argument to |
| ||(optional) A tensor or (possibly nested) sequence of tensors, as the initial value for the accumulator.|
| ||(optional) The number of iterations allowed to run in parallel.|
| || (optional) Deprecated. False disables support for back propagation. Prefer using |
| ||(optional) True enables GPU-CPU memory swapping.|
| ||(optional) Name prefix for the returned tensors.|
| A tensor or (possibly nested) sequence of tensors, resulting from applying |
| || if |
elems = [1, 2, 3, 4, 5, 6] sum = foldr(lambda a, x: a + x, elems) # sum == 21
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.