0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SciPy.linalg系関数に関するメモ

Last updated at Posted at 2020-06-15

SciPy.linalgでやりがちな(というか自分の踏んだ)ケアレスミスのメモ

逆行列 (Matrix inverse)

To obtain the matrix inverse, use linalg.pinv() instead of linalg.inv()

linalg.pinv の docs:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.pinv.html
linalg.inv の docs:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html
その他 Ref:
https://www.quora.com/What-is-the-difference-between-pinv-and-inv#:~:text=What%20is%20the%20difference%20between%20pinv%20and%20inv%3F,-ad%20b&text=pinv()%20function%20in%20OCTAVE,be%20an%20m*n%20matrix.


linalg.eig関数について

When using eigval, eigvec = scipy.linalg.eig(), the returned eigenvectors are in the columns of eigvec.
Supposing we want the first eigenvalue & eigenvector pair of a matrix my_matrix,

import scipy.linalg as la
eigval, eigvec = la.eig(my_matrix)

then we need

eigval_pair1 = eigval[0]
eigvec_pair1 = eigvec[:,0]

and NOT

eigvec_pair1 = eigvec[0]
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?