Is there a method that I can call to create a random orthonormal matrix in python? Possibly using numpy? Or is there a way to create a orthonormal matrix using multiple numpy methods? Thanks.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
if you want a none Square Matrix with orthonormal column vectors you could create a square one with any of the mentioned method and drop some columns.
This is the
rvs
method pulled from the https://github.com/scipy/scipy/pull/5622/files, with minimal change - just enough to run as a stand alone numpy function.It matches Warren's test, https://stackoverflow.com/a/38426572/901925
Version 0.18 of scipy has
scipy.stats.ortho_group
andscipy.stats.special_ortho_group
. The pull request where it was added is https://github.com/scipy/scipy/pull/5622For example,
You can obtain a random
n x n
orthogonal matrixQ
, (uniformly distributed over the manifold ofn x n
orthogonal matrices) by performing aQR
factorization of ann x n
matrix with elements i.i.d. Gaussian random variables of mean0
and variance1
. Here is an example:An easy way to create any shape (
n x m
) orthogonal matrix:Note that if
n > m
, it would obtainmat.T @ mat = eye(m)
.