set_value

paddle.Tensor. set_value ( self, value )
Notes:

This API is ONLY available in Dygraph mode

Set a new value for this Variable.

Parameters

value (Variable|np.ndarray) – the new value.

Examples

>>> import paddle.base as base
>>> import paddle
>>> from paddle.nn import Linear
>>> import numpy as np

>>> data = np.ones([3, 1024], dtype='float32')
>>> with base.dygraph.guard():
...     linear = Linear(1024, 4)
...     t = paddle.to_tensor(data)
...     linear(t)  # call with default weight
...     custom_weight = np.random.randn(1024, 4).astype("float32")
...     linear.weight.set_value(custom_weight)  # change existing weight
...     out = linear(t)  # call with different weight