mindspore.ops.svd

查看源文件
mindspore.ops.svd(input, full_matrices=False, compute_uv=True)[源代码]

计算单个或多个矩阵的奇异值分解。

设矩阵 A ,svd返回奇异值 S 、左奇异向量 U 和右奇异向量 V 。满足以下公式:

A=Udiag(S)VT
参数:
  • input (Tensor) - 输入tensor,shape为 (,M,N)

  • full_matrices (bool, 可选) - 如果为 True ,则计算完整的 UV 。否则仅计算前P个奇异向量,P为M和N中的较小值。默认 False

  • compute_uv (bool, 可选) - 如果为 True ,则计算 UV ,否则只计算 S 。默认 True

返回:

如果 compute_uvTrue ,返回三个tensor组成的tuple( s , u , v)。否则,返回单个tensor -> s

  • s 是奇异值tensor。shape为 (,P)

  • u 是左奇异tensor。如果 compute_uvFalse ,该值不会返回。shape为 (,M,P) 。如果 full_matricesTrue ,则shape为 (,M,M)

  • v 是右奇异tensor。如果 compute_uvFalse ,该值不会返回。shape为 (,N,P) 。如果 full_matricesTrue ,则shape为 (,N,N)

支持平台:

Ascend GPU CPU

样例:

>>> 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]]