mindspore.ops.svd
- mindspore.ops.svd(input, full_matrices=False, compute_uv=True)[source]
Computes the singular value decompositions of one or more matrices.
If
is a matrix, the svd returns the singular values , the left singular vectors and the right singular vectors . It meets:- Parameters
input (Tensor) – The input tensor, shape is
.full_matrices (bool, optional) – If
True
, compute full-sized and . IfFalse
, compute only the leading P singular vectors, with P is the minimum of M and N. DefaultFalse
.compute_uv (bool, optional) – If
True
, compute the left and right singular vectors. IfFalse
, compute only the singular values. DefaultTrue
.
- Returns
If compute_uv is
True
, a tuple( s , u , v ) of tensors will be returned. Otherwise, only a single tensor -> s will be returned.s is the singular value tensor. The shape is
.u is the left singular tensor. If compute_uv is
False
, u will not be returned. The shape is . If full_matrices isTrue
, the shape will be .v is the right singular tensor. If compute_uv is
False
, v will not be returned. The shape is . If full_matrices isTrue
, the shape will be .
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> input = mindspore.tensor([[1, 2], [-4, -5], [2, 1]], mindspore.float32) >>> s, u, v = mindspore.ops.svd(input, full_matrices=True, compute_uv=True) >>> print(s) [7.0652843 1.040081 ] >>> print(u) [[ 0.30821905 -0.48819482 0.81649697] [-0.90613353 0.11070572 0.40824813] [ 0.2896955 0.8656849 0.4082479 ]] >>> print(v) [[ 0.63863593 0.769509 ] [ 0.769509 -0.63863593]]