svdvals#
- ivy.svdvals(x, /, *, out=None)[source]#
Return the singular values of a matrix (or a stack of matrices)
x
.- Parameters:
- Return type:
- Returns:
ret – array with shape
(..., K)
that contains the vector(s) of singular values of lengthK
, where K = min(M, N). The values are sorted in descending order by magnitude.
This function conforms to the Array API Standard. This docstring is an extension of the docstring # noqa in the standard.
Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.Functional Examples
With
ivy.Array
input:>>> x = ivy.array([[5.0, 7.0], [4.0, 3.0]]) >>> S = ivy.svdvals(x) >>> print(S.shape) (2,)
With comparison of the singular value S ivy.svdvals() by the result ivy.svd().
>>> _, SS, _ = ivy.svd(x) >>> print(SS.shape) (2,)
>>> error = (SS - S).abs() >>> print(error) ivy.array([0.,0.])
With
ivy.NativeArray
input:>>> x = ivy.native_array([[1.0, 2.0, 3.0], [2.0, 3.0, 4.0], ... [2.0, 1.0, 3.0], [3.0, 4.0, 5.0]]) >>> print(x.shape) (4, 3)
>>> S = ivy.svdvals(x) >>> print(S) ivy.array([10.3, 1.16, 0.615])
>>> _, SS, _ = ivy.svd(x) >>> print(SS) ivy.array([10.3, 1.16, 0.615])
with comparison of singular value S ivy.svdvals() by the result ivy.svd().
>>> error = (SS - S).abs() >>> print(error) ivy.array([0., 0., 0.])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([[2.0, 3.0], [3.0, 4.0], ... [1.0, 3.0], [3.0, 5.0]]), ... b=ivy.array([[7.0, 1.0, 2.0, 3.0], ... [2.0, 5.0, 3.0, 4.0], ... [2.0, 6.0, 1.0, 3.0], ... [3.0, 4.0, 5.0, 9.0]])) >>> y = ivy.svdvals(x) >>> print(y) { a: ivy.array([9.01, 0.866]), b: ivy.array([15.8, 5.56, 4.17, 0.864]) }
Instance Method Examples
Using
ivy.Array
instance method:>>> x = ivy.array([[8.0, 3.0], [2.0, 3.0], ... [2.0, 1.0], [3.0, 4.0], ... [4.0, 1.0], [5.0, 6.0]]) >>> y = x.svdvals() >>> print(y) ivy.array([13.4, 3.88])
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([[2.0, 3.0, 6.0], [5.0, 3.0, 4.0], ... [1.0, 7.0, 3.0], [3.0, 2.0, 5.0]]), ... b=ivy.array([[7.0, 1.0, 2.0, 3.0, 9.0], ... [2.0, 5.0, 3.0, 4.0, 10.0], ... [2.0, 11.0, 6.0, 1.0, 3.0], ... [8.0, 3.0, 4.0, 5.0, 9.0]])) >>> y = x.svdvals() >>> print(y) { a: ivy.array([13., 4.64, 2.55]), b: ivy.array([23.2, 10.4, 4.31, 1.36]) }
- Array.svdvals(self, /, *, out=None)#
- Return type:
Array
- Container.svdvals(self, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
- Return type:
Container