venkysmarty
venkysmarty

Reputation: 11431

singular values in svd calculation using numpy

I have a question for following

A = array([
[1,2,3,4,5,6,7,8,9,10],
[11,12,13,14,15,16,17,18,19,20],
[21,22,23,24,25,26,27,28,29,30]])
print(A)
# Singular-value decomposition
U, s, VT = svd(A)

For above “s” should be of shape(10,) as we have 10 features, but instead of (3,) is shown. Sample output is shown below I am confused. Kindly explain, why we go (3,)

(3, 10)
U shape (3, 3)
s shape (3,)
VT shape (10, 10)

Let us consider another example

A = array([[1, 2], [3, 4], [5, 6]])
print(A.shape)
# Singular-value decomposition
U, s, VT = svd(A)
Here “s” shape is shown as (2,)

Here output is shown below

(3, 2)
U shape  (3, 3)
s shape (2,)
VT shape  (2, 2)

I am not getting why there is difference in shape. Kindly expalin

Upvotes: 0

Views: 341

Answers (1)

Nils Werner
Nils Werner

Reputation: 36719

Using SVD, a matrix A of shape (m x n) is decomposed into

  • a unitary matrix U of shape (m x m)
  • a rectangular diagonal matrix Sigma of shape (m x n)
  • a unitary matrix V of shape (n x n)

Sigma contains all singular values on its main diagonal. Since a matrix of shape (m x n) only contains min(m, n) elements on its main diagonal, there are only min(m, n) singular values.

Upvotes: 1

Related Questions