| View source on GitHub | 
Computes the singular value decompositions of one or more matrices.
tf.linalg.svd(
    tensor, full_matrices=False, compute_uv=True, name=None
)
  Computes the SVD of each inner matrix in tensor such that tensor[..., :, :] = u[..., :, :] * diag(s[..., :, :]) * transpose(conj(v[..., :, :]))
# a is a tensor. # s is a tensor of singular values. # u is a tensor of left singular vectors. # v is a tensor of right singular vectors. s, u, v = svd(a) s = svd(a, compute_uv=False)
| Args | |
|---|---|
| tensor | Tensorof shape[..., M, N]. LetPbe the minimum ofMandN. | 
| full_matrices | If true, compute full-sized uandv. If false (the default), compute only the leadingPsingular vectors. Ignored ifcompute_uvisFalse. | 
| compute_uv | If Truethen left and right singular vectors will be computed and returned inuandv, respectively. Otherwise, only the singular values will be computed, which can be significantly faster. | 
| name | string, optional name of the operation. | 
| Returns | |
|---|---|
| s | Singular values. Shape is [..., P]. The values are sorted in reverse order of magnitude, so s[..., 0] is the largest value, s[..., 1] is the second largest, etc. | 
| u | Left singular vectors. If full_matricesisFalse(default) then shape is[..., M, P]; iffull_matricesisTruethen shape is[..., M, M]. Not returned ifcompute_uvisFalse. | 
| v | Right singular vectors. If full_matricesisFalse(default) then shape is[..., N, P]. Iffull_matricesisTruethen shape is[..., N, N]. Not returned ifcompute_uvisFalse. | 
numpy compatibility
Mostly equivalent to numpy.linalg.svd, except that
s, u, v when compute_uv is True, as opposed to u, s, v for numpy.linalg.svd.False by default as opposed to True for numpy.linalg.svd.a are the columns of u, while the right singular vectors of a are the columns of v. On the other hand, numpy.linalg.svd returns the adjoint \(V^H\) as the third output argument.import tensorflow as tf import numpy as np s, u, v = tf.linalg.svd(a) tf_a_approx = tf.matmul(u, tf.matmul(tf.linalg.diag(s), v, adjoint_b=True)) u, s, v_adj = np.linalg.svd(a, full_matrices=False) np_a_approx = np.dot(u, np.dot(np.diag(s), v_adj)) # tf_a_approx and np_a_approx should be numerically close.
    © 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
    https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/linalg/svd