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.MatrixDiagPartV3

View Source On Gitee
class mindspore.ops.MatrixDiagPartV3(align='RIGHT_LEFT')[source]

Returns the diagonal part of a tensor.

Warning

This is an experimental API that is subject to change or deletion.

Refer to mindspore.ops.matrix_diag_part() for more details.

Parameters

align (str, optional) –

specifies how superdiagonals and subdiagonals should be aligned. Supported values: "RIGHT_LEFT" , "LEFT_RIGHT" , "LEFT_LEFT" , "RIGHT_RIGHT" . Default: "RIGHT_LEFT" .

  • When set to "RIGHT_LEFT" , the alignment of superdiagonals will be towards the right side (padding the row on the left), while subdiagonals will be towards the left side (padding the row on the right)

  • When set to "LEFT_RIGHT" , the alignment of superdiagonals will be towards the left side (padding the row on the right), while subdiagonals will be towards the right side (padding the row on the left)

  • When set to "LEFT_LEFT" , the alignment of both superdiagonals and subdiagonals will be towards the left side(padding the row on the right).

  • When set to "RIGHT_RIGHT" , the alignment of both superdiagonals and subdiagonals will be towards the right side(padding the row on the left).

Inputs:
  • x (Tensor) - Rank r, where r >= 2.

  • k (Tensor) - A Tensor of type int32. Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main diagonal, and negative value means subdiagonals. k can be a single integer (for a single diagonal) or a pair of integers specifying the low and high ends of a matrix band. k[0] must not be larger than k[1]. The value of k has restructions, meaning value of k must be in (-x.shape[-2], x.shape[-1]).

  • padding_value (Tensor) - A Tensor. Have the same dtype as x. The number to fill the area outside the specified diagonal band with. There must be only one value.

Outputs:

A Tensor. Has the same type as x. Assume x has r dimensions (I,J,...,M,N) . Let max_diag_len be the maximum length among all diagonals to be extracted, max_diag_len=min(M+min(k[1],0),N+min(k[0],0)) Let num_diags be the number of diagonals to extract, num_diags=k[1]k[0]+1. If num_diags==1, the output tensor is of rank r - 1 with shape (I,J,...,L,max_diag_len) Otherwise, the output tensor has rank r with dimensions (I,J,...,L,num_diags,max_diag_len) .

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([[1, 2, 3, 4],
...                      [5, 6, 7, 8],
...                      [9, 8, 7, 6]]), mindspore.float32)
>>> k =Tensor(np.array([1, 3]), mindspore.int32)
>>> padding_value = Tensor(np.array(9), mindspore.float32)
>>> matrix_diag_part_v3 = ops.MatrixDiagPartV3(align='RIGHT_LEFT')
>>> output = matrix_diag_part_v3(x, k, padding_value)
>>> print(output)
[[9. 9. 4.]
 [9. 3. 8.]
 [2. 7. 6.]]
>>> print(output.shape)
(3, 3)