megengine.functional.svd¶
- svd(inp, full_matrices=False, compute_uv=True)[源代码]¶
返回一个矩阵
x``(或一个矩阵堆) 的奇异值分解 ``A = USVh
, 其中U
是一个具有正交列的矩阵 (或一个矩阵堆) ,S
是一个非负数的向量 (或一个向量堆),Vh
是一个具有正交行的矩阵 (或一个矩阵堆)。- 参数
注解
不支持
full_matrices``和 ``compute_uv
为True
.
- 返回类型
- 返回
返回一个元组 (
U
,S
,Vh
),U
,S
,Vh
是输入x``的SVD因子 。 ( ``U
,Vh
只有当``compute_uv`` 是 True时返回).。U
包含矩阵正交列 (即,列是左奇异向量)。如果full_matrices
是True
, 数组的shape必须是(..., M, M)
. 如果full_matrices
是False
, 数组的shape必须是(..., M, K)
, 其中K = min(M, N)
。
实际案例
>>> import numpy as np >>> x = Tensor(np.random.randn(9, 6)) >>> y = Tensor(np.random.randn(2, 7, 8, 3))
基于 reduced SVD, 2D 情形的重构: >>> U, S, Vh = F.svd(x, full_matrices=False) >>> print(U._tuple_shape, S._tuple_shape, Vh._tuple_shape) (9, 6) (6,) (6, 6)
基于 reduced SVD, 4D 情形的重构: >>> u, s, vh = F.svd(y, full_matrices=False) >>> print(u._tuple_shape, s._tuple_shape, vh._tuple_shape) (2, 7, 8, 3) (2, 7, 3) (2, 7, 3, 3)