mindspore.ops.diagonal_scatter

View Source On Gitee
mindspore.ops.diagonal_scatter(input, src, offset=0, dim1=0, dim2=1)[source]

Embeds the values of the src tensor into input along the diagonal elements of input, with respect to dim1 and dim2 .

Note

Currently, inf value of elements in input or src is not supported.

Parameters
  • input (Tensor) – The input tensor, whose dimension is larger than 1.

  • src (Tensor) – The source tensor to embed.

  • offset (int, optional) –

    Diagonal offset. Default 0 .

    • When offset is a positive integer, shift the diagonal upward.

    • When offset is a negative integer, shift the diagonal downward.

  • dim1 (int, optional) – First dimension with respect to which to take diagonal. Default 0 .

  • dim2 (int, optional) – Second dimension with respect to which to take diagonal. Default 1 .

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input = mindspore.ops.zeros((3, 3))
>>> output = mindspore.ops.diagonal_scatter(input, mindspore.ops.ones(3), 0)
>>> print(output)
[[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]
>>> output = mindspore.ops.diagonal_scatter(input, mindspore.ops.ones(2), 1)
>>> print(output)
[[0. 1. 0.]
 [0. 0. 1.]
 [0. 0. 0.]]