assign

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

The OP copies the input to the output.

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

  • output (Tensor, 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

Tensor

Examples

import paddle
import numpy as np
data = paddle.full(shape=[3, 2], fill_value=2.5, dtype='float64') # [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
array = np.array([[1, 1],
                  [3, 4],
                  [1, 3]]).astype(np.int64)
result1 = paddle.zeros(shape=[3, 3], dtype='float32')
paddle.assign(array, result1) # result1 = [[1, 1], [3 4], [1, 3]]
result2 = paddle.assign(data)  # result2 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
result3 = paddle.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]]