mindspore.ops.cond

View Source On Gitee
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 or float

– not supported –

sum(abs(x)p)(1/p)

Note

Currently, complex numbers are not supported.

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

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

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'))
3.1622777