Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.diag_embed

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

Creates a tensor with diagonals filled by input. The remaining elements are filled by 0. If the shape of input is [x0,x1,...,xn1,xn], the output shape is: the vector obtained by inserting xn+|offset| into the vector [x0,x1,...,xn1] at position dim1 and dim2.

Parameters
  • input (Tensor) – Values to fill diagonal.

  • offset (int, optional) –

    Offset of the diagonal. offset=0 refers to the main diagonal. Default: 0 .

    • If offset>0, fill the diagonals that are offset units upward from the main diagonal.

    • If offset<0, fill the diagonals that are |offset| units downward from the main diagonal.

  • dim1 (int, optional) – The first dimension in input with respect to which to fill diagonal. Default: -2 .

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

Returns

Tensor, has the same dtype as input, but the shape of output is one dimension higher than the input.

Raises
  • TypeError – If input is not a Tensor.

  • TypeError – If dtype of input is not supported.

  • TypeError – If offset is not an int.

  • TypeError – If dim1 or dim2 is not an int.

  • ValueError – If the dimension of input is not 1D-6D.

  • ValueError – If dim1 is not in range of [-len(input.shape) - 1, len(input.shape)].

  • ValueError – If dim2 is not in range of [-len(input.shape) - 1, len(input.shape)].

  • ValueError – If dim1 and dim2 are identical.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([2,3,4]), mindspore.float32)
>>> output = ops.diag_embed(x)
>>> print(output)
[[2. 0. 0.]
 [0. 3. 0.]
 [0. 0. 4.]]