linear_algebra.py :  » Math » Numerical-Python » numpy » numpy » oldnumeric » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Math » Numerical Python 
Numerical Python » numpy » numpy » oldnumeric » linear_algebra.py
"""Backward compatible with LinearAlgebra from Numeric
"""
# This module is a lite version of the linalg.py module in SciPy which contains
# high-level Python interface to the LAPACK library.  The lite version
# only accesses the following LAPACK functions: dgesv, zgesv, dgeev,
# zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf.


__all__ = ['LinAlgError', 'solve_linear_equations',
           'inverse', 'cholesky_decomposition', 'eigenvalues',
           'Heigenvalues', 'generalized_inverse',
           'determinant', 'singular_value_decomposition',
           'eigenvectors',  'Heigenvectors',
           'linear_least_squares'
           ]

from numpy.core import transpose
import numpy.linalg as linalg

# Linear equations

LinAlgError = linalg.LinAlgError

def solve_linear_equations(a, b):
    return linalg.solve(a,b)

# Matrix inversion

def inverse(a):
    return linalg.inv(a)

# Cholesky decomposition

def cholesky_decomposition(a):
    return linalg.cholesky(a)

# Eigenvalues

def eigenvalues(a):
    return linalg.eigvals(a)

def Heigenvalues(a, UPLO='L'):
    return linalg.eigvalsh(a,UPLO)

# Eigenvectors

def eigenvectors(A):
    w, v = linalg.eig(A)
    return w, transpose(v)

def Heigenvectors(A):
    w, v = linalg.eigh(A)
    return w, transpose(v)

# Generalized inverse

def generalized_inverse(a, rcond = 1.e-10):
    return linalg.pinv(a, rcond)

# Determinant

def determinant(a):
    return linalg.det(a)

# Linear Least Squares

def linear_least_squares(a, b, rcond=1.e-10):
    """returns x,resids,rank,s
where x minimizes 2-norm(|b - Ax|)
      resids is the sum square residuals
      rank is the rank of A
      s is the rank of the singular values of A in descending order

If b is a matrix then x is also a matrix with corresponding columns.
If the rank of A is less than the number of columns of A or greater than
the number of rows, then residuals will be returned as an empty array
otherwise resids = sum((b-dot(A,x)**2).
Singular values less than s[0]*rcond are treated as zero.
"""
    return linalg.lstsq(a,b,rcond)

def singular_value_decomposition(A, full_matrices=0):
    return linalg.svd(A, full_matrices)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.