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.

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.mint.linalg.matrix_norm

mindspore.mint.linalg.matrix_norm(A, ord='fro', dim=(- 2, - 1), keepdim=False, *, dtype=None)[source]

Returns the matrix norm of a given tensor on the specified dimensions.

ord is the calculation mode of norm. The following norm modes are supported.

ord

norm for matrix

'fro' (Default)

Frobenius norm

'nuc'

nuclear norm

inf

max(sum(abs(x),dim=1))

-inf

min(sum(abs(x),dim=1))

1

max(sum(abs(x),dim=0))

-1

min(sum(abs(x),dim=0))

2

largest singular value

-2

smallest singular value

Warning

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

Parameters
  • A (Tensor) – Tensor of shape (,m,n) where * is zero or more batch dimensions.

  • ord (Union[int, inf, -inf, 'fro', 'nuc'], optional) – norm's mode. refer to the table above for behavior. Default: 'fro' .

  • dim (Tuple(int, int), optional) – calculate the dimension of the matrix norm. Default: (-2, -1) .

  • keepdim (bool) – whether the output Tensor retains the original dimension. Default: False .

Keyword Arguments

dtype (mindspore.dtype, optional) – When set, A will be converted to the specified type, dtype, before execution, and dtype of returned Tensor will also be dtype. When dtype is None , the dtype of A is preserved. Default: None .

Returns

Tensor, the result of norm calculation on the specified dimension, dim.

Raises
  • TypeError – If dim is not a tuple of int.

  • ValueError – If the length of dim is not equal to 2.

  • ValueError – If ord is not in [2, -2, 1, -1, float('inf'), float('-inf'), 'fro', 'nuc'].

  • ValueError – If two elements of dim is same after normalize.

  • ValueError – If any elements of dim is out of range.

Note

Dynamic shape, Dynamic rank and mutable input is not supported in graph mode (mode=mindspore.GRAPH_MODE).

Supported Platforms:

Ascend

Examples

>>> import mindspore as ms
>>> A = ms.ops.arange(0, 12, dtype=ms.float32).reshape(3, 4)
>>> print(ms.mint.linalg.matrix_norm(A, ord='fro'))
22.494444
>>> print(ms.mint.linalg.matrix_norm(A, ord='nuc'))
24.364643
>>> print(ms.mint.linalg.matrix_norm(A, ord=float('inf')))
38.0
>>> print(ms.mint.linalg.matrix_norm(A, ord=float('-inf')))
6.0