5

numpy.linalg.svd function gives the full svd of the input matrix. However I want only the first singular vectors.

I was wondering if there is any function in numpy for that or any other library in python?

Harit Vishwakarma
  • 2,338
  • 4
  • 21
  • 36

2 Answers2

3

One possibility is sklearn.utils.extmath.randomized_svd

from sklearn.utils.extmath import randomized_svd
U, S, Vt = randomized_svd(X, n_components=1)
JARS
  • 1,109
  • 7
  • 10
3

In addition to randomized svd, you can run ARPACK on the squared problem, via scipy.sparse.linalg.svds.

pv.
  • 33,875
  • 8
  • 55
  • 49