mindspore.ops.svd
- mindspore.ops.svd(input, full_matrices=False, compute_uv=True)[源代码]
计算单个或多个矩阵的奇异值分解。
设矩阵
,svd返回奇异值 、左奇异向量 和右奇异向量 。满足以下公式:- 参数:
input (Tensor) - 输入tensor,shape为
。full_matrices (bool, 可选) - 如果为
True
,则计算完整的 和 。否则仅计算前P个奇异向量,P为M和N中的较小值。默认False
。compute_uv (bool, 可选) - 如果为
True
,则计算 和 ,否则只计算 。默认True
。
- 返回:
如果 compute_uv 为
True
,返回三个tensor组成的tuple( s , u , v)。否则,返回单个tensor -> s 。s 是奇异值tensor。shape为
。u 是左奇异tensor。如果 compute_uv 为
False
,该值不会返回。shape为 。如果 full_matrices 为True
,则shape为 。v 是右奇异tensor。如果 compute_uv 为
False
,该值不会返回。shape为 。如果 full_matrices 为True
,则shape为 。
- 支持平台:
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]]