fill_diagonal_

paddle.Tensor. fill_diagonal_ ( x, value, offset=0, wrap=False, name=None )

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 Tensor

  • value (Scale) – value is the value to filled in x

  • offset (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,optional) – Name for the operation (optional, default is None)

Returns

Tensor, Tensor with diagonal filled with value.

Examples

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/tensor/manipulation.py:docstring of paddle.tensor.manipulation.fill_diagonal_, line 20)

Error in “code-block” directive: maximum 1 argument(s) allowed, 23 supplied.

.. code-block:: python
    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]]