assign

paddle.fluid.layers.assign(input, output=None)[source]

The OP copies the input to the output.

Parameters
  • input (Variable|numpy.ndarray) – A tensor or numpy ndarray, its data type supports float32, float64, int32 and int64.

  • output (Variable, optional) – A tensor. If output is None, a new tensor will be created as output. Default: None.

Returns

A tensor with the same shape, data type and value as input.

Return type

Variable

Examples

import paddle.fluid as fluid
import numpy as np
data = fluid.layers.fill_constant(shape=[3, 2], value=2.5, dtype='float64') # [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
result1 = fluid.layers.create_tensor(dtype='float64')
fluid.layers.assign(data, result1) # result1 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
result2 = fluid.layers.assign(data)  # result2 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
result3 = fluid.layers.assign(np.array([[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]], dtype='float32')) # result3 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]