[PYTHON] Notes on SciPy.linalg functions

A note of careless mistakes that you tend to do with 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 Other 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.


About the linalg.eig function

--The eigenvector is returned vertically as a matrix with the linalg.eig function.

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]

Recommended Posts

Notes on SciPy.linalg functions
[Golang] Notes on frequently used functions
Notes on Flask
Notes on neural networks
Celery notes on Django
Notes on installing PycURL
Notes on using Alembic
Notes on tf.function and Tracing
Notes on python's sqlite3 module
Notes on * args and ** kargs
Notes on defining PySide slots (2)
[Django] Notes on using django-debug-toolbar
Notes on pyenv and Atom
Notes on defining PySide slots
Notes on optimization using Pytorch
Notes on installing Python on Mac
Notes on studying multidimensional scaling
Notes on installing pipenv on Mac
Notes on installing Anaconda 3 on Windows
Notes on imshow () in OpenCV
Notes on installing Python on CentOS
Notes on Python and dictionary types
Notes on package management with conda
Notes on using MeCab from Python
Notes on how to use pywinauto
Memorandum on Memoization of recursive functions
Notes on using post-receive and post-merge
Notes on how to use featuretools
Notes on installing Python using PyEnv
Notes on using rstrip with python.
Notes on accessing dashDB from python
Notes on how to use doctest
Notes on using matplotlib on the server
Notes on how to write requirements.txt
Notes on installing Ubuntu 18.04 on the XPS 15 7590
(Beginner) Notes on using pyenv on Mac
Restart only network functions on Mac
Notes for using OpenCV on Windows10 Python 3.8.3.
Notes on PyQ machine learning python grammar
Notes on running M5Stick V with uPyLoader
Notes on nfc.ContactlessFrontend () for nfcpy in python
Notes for installing Sublime Text on Ubuntu
Notes on standard input / output of Go
Notes on running Azure Machine Learning locally
Notes on doing Japanese OCR with Python
Notes on building Python and pyenv on Mac
Notes on implementing APNs tests using Pytest
Notes on using OpenCL on Linux on the RX6800
Notes on KL divergence between Poisson distributions
Notes for setting up pydicom on macOS
Import your own functions on AWS Glue
Notes on using code formatter in Python