MCPcopy Create free account
hub / github.com/dask/dask / svd

Function svd

dask/array/linalg.py:874–962  ·  view source on GitHub ↗

Compute the singular value decomposition of a matrix. Parameters ---------- a : (M, N) Array coerce_signs : bool Whether or not to apply sign coercion to singular vectors in order to maintain deterministic results, by default True. Examples --------

(a, coerce_signs=True)

Source from the content-addressed store, hash-verified

872
873
874def svd(a, coerce_signs=True):
875 """
876 Compute the singular value decomposition of a matrix.
877
878 Parameters
879 ----------
880 a : (M, N) Array
881 coerce_signs : bool
882 Whether or not to apply sign coercion to singular vectors in
883 order to maintain deterministic results, by default True.
884
885 Examples
886 --------
887
888 >>> u, s, v = da.linalg.svd(x) # doctest: +SKIP
889
890 Returns
891 -------
892
893 u : (M, K) Array, unitary / orthogonal
894 Left-singular vectors of `a` (in columns) with shape (M, K)
895 where K = min(M, N).
896 s : (K,) Array, singular values in decreasing order (largest first)
897 Singular values of `a`.
898 v : (K, N) Array, unitary / orthogonal
899 Right-singular vectors of `a` (in rows) with shape (K, N)
900 where K = min(M, N).
901
902 Warnings
903 --------
904
905 SVD is only supported for arrays with chunking in one dimension.
906 This requires that all inputs either contain a single column
907 of chunks (tall-and-skinny) or a single row of chunks (short-and-fat).
908 For arrays with chunking in both dimensions, see da.linalg.svd_compressed.
909
910 See Also
911 --------
912
913 np.linalg.svd : Equivalent NumPy Operation
914 da.linalg.svd_compressed : Randomized SVD for fully chunked arrays
915 dask.array.linalg.tsqr : QR factorization for tall-and-skinny arrays
916 dask.array.utils.svd_flip : Sign normalization for singular vectors
917 """
918 nb = a.numblocks
919 if a.ndim != 2:
920 raise ValueError(
921 f"Array must be 2D.\nInput shape: {a.shape}\nInput ndim: {a.ndim}\n"
922 )
923 if nb[0] > 1 and nb[1] > 1:
924 raise NotImplementedError(
925 "Array must be chunked in one dimension only. "
926 "This function (svd) only supports tall-and-skinny or short-and-fat "
927 "matrices (see da.linalg.svd_compressed for SVD on fully chunked arrays).\n"
928 f"Input shape: {a.shape}\n"
929 f"Input numblocks: {nb}\n"
930 )
931

Callers 3

normFunction · 0.85

Calls 5

delayedFunction · 0.90
from_delayedFunction · 0.90
svd_flipFunction · 0.90
minFunction · 0.85
tsqrFunction · 0.85

Tested by 2