LoginSignup
8
5

More than 5 years have passed since last update.

scipy.sparse.linalg.svds は特異値を昇順で返す

Posted at

numpy.linalg.svd, scipy.linalg.svd は降順で返す一方で、 scipy.sparse.linalg.svds は昇順で返すので注意。はまりました。

動作確認用のコード

# coding: utf-8

import numpy as np
import scipy.linalg
import scipy.sparse.linalg

x = np.random.rand(7, 7)

U, S1, V = np.linalg.svd(x)
print S1

U, S2, V = scipy.linalg.svd(x)
print S2

U, S3, V = scipy.sparse.linalg.svds(x)
print S3

# S1, S2と等しくなる
print S3[::-1]

降順にしたい場合

A. 自分で書く(降順にするオプションはありませんでした

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5