assign

paddle. assign ( x, output=None ) [source]

Copy value of the x to the output.

Parameters
  • x (Tensor|np.ndarray|list|tuple|scalar) – A Tensor, numpy ndarray, tuple/list of scalar, or scalar. Its data type can be float16, float32, float64, int32, int64 or bool. Note: the float64 data will be converted to float32 because of current platform protobuf data limitation.

  • 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 x.

Return type

Tensor

Examples

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