Constant

class paddle.nn.initializer. Constant ( value=0.0 ) [source]

Implement the constant initializer.

Parameters

value (float32|float64, optional) – constant value to initialize the parameter. Default: 0.0.

Examples

>>> import paddle
>>> import paddle.nn as nn

>>> paddle.seed(2023)
>>> data = paddle.rand([30, 10, 2], dtype='float32')
>>> linear = nn.Linear(2,
...                     4,
...                     weight_attr=nn.initializer.Constant(value=2.0))
>>> res = linear(data)
>>> print(linear.weight)
Parameter containing:
Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=False,
[[2., 2., 2., 2.],
 [2., 2., 2., 2.]])