partial_sum¶
- paddle.fluid.contrib.layers.nn. partial_sum ( input, start_index=0, length=- 1 ) [source]
-
PartialSum This Op can sum the vars by specifying the initial position(start_index) and length(length). This Op exists in contrib, which means that it is not shown to the public. Only 2-D Tensor or LodTensor input is supported. Slice and concat can only be performed along the second dimension. .. code-block:: text
- Given:
-
- x = [[0, 1, 2],
-
[3, 4, 5]]
- y = [[6, 7 ,8],
-
[9, 10, 11]]
output = partial_sum([x, y], start_index=0, length=2)
we get:
- output = [[6, 8],
-
[12, 14]]
- Parameters
-
input (list) – List of input Tensors with data type float32, float64, int32, int64.
- Returns
-
A Tensor with the same data type as input’s.
- Return type
-
Variable
Examples
import paddle.fluid.layers as layers import paddle.fluid as fluid import numpy as np x = fluid.data(name=”x”, shape=[None, 3], dtype=”float32”) y = fluid.data(name=”y”, shape=[None, 3], dtype=”float32”) sum = layers.partial_sum([x,y], start_index=0, length=2) place = fluid.CPUPlace() exe = fluid.Executor(place) xx = np.array([1,2,3,4,5,6]).reshape((2,3)).astype(“float32”) yy = np.array([6,5,4,4,5,6]).reshape((2,3)).astype(“float32”) out = exe.run(feed={“x”:xx, “y”:yy}, fetch_list=[sum])