All examples in this section assume that you performed a
from numarray import * import numarray.linear_algebra as la
a) |
a
; a
must be
square, Hermitian, and positive definite. L is often referred to as the
Cholesky lower-triangular square-root of a
.
a) |
a
.
>>> print a [[ 1 2] [ 3 15]] >>> print la.determinant(a) 9.0
a) |
a
.
>>> print a [[ 1. 0. 0. 0. ] [ 0. 2. 0. 0.01] [ 0. 0. 5. 0. ] [ 0. 0.01 0. 2.5 ]] >>> print la.eigenvalues(a) [ 2.50019992 1.99980008 1. 5. ]
a) |
>>> print a [[ 1. 0. 0. 0. ] [ 0. 2. 0. 0.01] [ 0. 0. 5. 0. ] [ 0. 0.01 0. 2.5 ]] >>> eval, evec = la.eigenvectors(a) >>> print eval # same as eigenvalues() [ 2.50019992 1.99980008 1. 5. ] >>> print transpose(evec) [[ 0. 0. 1. 0. ] [ 0.01998801 0.99980022 0. 0. ] [ 0. 0. 0. 1. ] [ 0.99980022 -0.01998801 0. 0. ]]
a, rcond=1e-10) |
a
. It has numerous
applications related to linear equations and least-squares problems.
>>> ainv = la.generalized_inverse(a) >>> print array_str(innerproduct(a,ainv),suppress_small=1,precision=8) [[ 1. 0. 0. 0.] [ 0. 1. 0. -0.] [ 0. 0. 1. 0.] [ 0. -0. 0. 1.]]
a) |
a) |
a) |
matrixmultiply(a, inverse(a)) ==
identity(len(a))
. To test this claim, one can do e.g.:
>>> a = reshape(arange(25.0), (5,5)) + identity(5) >>> print a [[ 1. 1. 2. 3. 4.] [ 5. 7. 7. 8. 9.] [ 10. 11. 13. 13. 14.] [ 15. 16. 17. 19. 19.] [ 20. 21. 22. 23. 25.]] >>> inv_a = la.inverse(a) >>> print inv_a [[ 0.20634921 -0.52380952 -0.25396825 0.01587302 0.28571429] [-0.5026455 0.63492063 -0.22751323 -0.08994709 0.04761905] [-0.21164021 -0.20634921 0.7989418 -0.1957672 -0.19047619] [ 0.07936508 -0.04761905 -0.17460317 0.6984127 -0.42857143] [ 0.37037037 0.11111111 -0.14814815 -0.40740741 0.33333333]]
>>> print "Inversion error:", maximum.reduce(fabs(ravel(dot(a, inv_a)-identity(5)))) Inversion error: 8.18789480661e-16
a, b, rcond=1e-10) |
a, b) |
a, full_matrices=0) |
Send comments to the NumArray community.