diagonal_scatter

paddle. diagonal_scatter ( x, y, offset=0, axis1=0, axis2=1, name=None ) [source]

Embed the values of Tensor y into Tensor x along the diagonal elements of Tensor x, with respect to axis1 and axis2.

This function returns a tensor with fresh storage.

The argument offset controls which diagonal to consider:

  • If offset = 0, it is the main diagonal.

  • If offset > 0, it is above the main diagonal.

  • If offset < 0, it is below the main diagonal.

Note

y should have the same shape as paddle.diagonal.

Parameters
  • x (Tensor) – x is the original Tensor. Must be at least 2-dimensional.

  • y (Tensor) – y is the Tensor to embed into x

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

  • axis1 (int, optional) – first axis with respect to which to take diagonal. Default: 0.

  • axis2 (int, optional) – second axis with respect to which to take diagonal. Default: 1.

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

Returns

Tensor, Tensor with diagonal embedeed with y.

Examples

>>> import paddle
>>> x = paddle.arange(6.0).reshape((2, 3))
>>> y = paddle.ones((2,))
>>> out = x.diagonal_scatter(y)
>>> print(out)
Tensor(shape=[2, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [[1., 1., 2.],
        [3., 1., 5.]])