fill_diagonal_¶
- paddle.Tensor. fill_diagonal_ ( x: Tensor, value: float, offset: int = 0, wrap: bool = False, name: str | None = None ) Tensor
-
Note
This API is ONLY available in Dygraph mode.
This function fill the value into the x Tensor’s diagonal inplace.
- Parameters
-
x (Tensor) –
x
is the original Tensorvalue (int|float) –
value
is the value to filled in xoffset (int,optional) – the offset to the main diagonal. Default: 0 (main diagonal).
wrap (bool,optional) – the diagonal ‘wrapped’ after N columns for tall matrices.
name (str|None,optional) – Name for the operation (optional, default is None)
- Returns
-
Tensor, Tensor with diagonal filled with value.
Examples
>>> import paddle >>> x = paddle.ones((4, 3)) * 2 >>> x.fill_diagonal_(1.0) >>> print(x.tolist()) [[1.0, 2.0, 2.0], [2.0, 1.0, 2.0], [2.0, 2.0, 1.0], [2.0, 2.0, 2.0]]