fill_diagonal_tensor

paddle.Tensor. fill_diagonal_tensor ( x, y, offset=0, dim1=0, dim2=1, name=None )

This function fill the source Tensor y into the x Tensor’s diagonal.

Parameters
  • x (Tensor) – x is the original Tensor

  • y (Tensor) – y is the Tensor to filled in x

  • dim1 (int,optional) – first dimension with respect to which to fill diagonal. Default: 0.

  • dim2 (int,optional) – second dimension with respect to which to fill diagonal. Default: 1.

  • offset (int,optional) – the offset to the main diagonal. Default: 0 (main diagonal).

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Tensor, Tensor with diagonal filled with y.

Examples

>>> import paddle

>>> x = paddle.ones((4, 3)) * 2
>>> y = paddle.ones((3,))
>>> nx = x.fill_diagonal_tensor(y)
>>> print(nx.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]]