mindspore.ops.cond
- mindspore.ops.cond(A, p=None)[source]
Returns the matrix norm or vector norm of a given tensor.
p is the calculation mode of norm. The following norm modes are supported.
p
norm for matrices
norm for vectors
None
(default)2-norm (see below)
2-norm (see below)
'fro'
Frobenius norm
– not supported –
'nuc'
nuclear norm
– not supported –
inf
\(max(sum(abs(x), dim=1))\)
\(max(abs(x))\)
-inf
\(min(sum(abs(x), dim=1))\)
\(min(abs(x))\)
0
– not supported –
\(sum(x != 0)\)
1
\(max(sum(abs(x), dim=0))\)
as below
-1
\(min(sum(abs(x), dim=0))\)
as below
2
largest singular value
as below
-2
smallest singular value
as below
other
int
orfloat
– not supported –
\(sum(abs(x)^{p})^{(1 / p)}\)
Note
Currently, complex numbers are not supported.
- Parameters
- Returns
Tensor, the result of norm calculation on the specified dimension, dim, has the same dtype as A.
- Raises
TypeError – If A is a vector and p is a str.
ValueError – If A is a matrices and p is not in valid mode.
ValueError – If A is a matrix and p is an integer that is not in [1, -1, 2, -2].
- Supported Platforms:
GPU
CPU
Examples
>>> import mindspore as ms >>> x = ms.Tensor([[1.0, 0.0, -1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 1.0]]) >>> print(ms.ops.cond(x)) 1.4142 >>> print(ms.ops.cond(x, 'fro')) 1.1623