[Numpy-discussion] question about the documentation of linalg.solve
Wed Nov 19 09:46:37 CST 2008
If you use iPython and use "numpy.linalg.solve??", you can see the
source code of the file numpy/linalg/linalg.py that corresponds to the
solve(a,b) function, not just the docstring:
def solve(a, b):
Solve the equation ``a x = b`` for ``x``.
a : array_like, shape (M, M)
Input equation coefficients.
b : array_like, shape (M,)
Equation target values.
x : array, shape (M,)
If `a` is singular or not square.
Solve the system of equations ``3 * x0 + x1 = 9`` and ``x0 + 2 * x1 = 8``:
>>> a = np.array([[3,1], [1,2]])
>>> b = np.array([9,8])
>>> x = np.linalg.solve(a, b)
array([ 2., 3.])
Check that the solution is correct:
>>> (np.dot(a, x) == b).all()
a, _ = _makearray(a)
b, wrap = _makearray(b)
one_eq = len(b.shape) == 1
b = b[:, newaxis]
n_eq = a.shape
n_rhs = b.shape
if n_eq != b.shape:
raise LinAlgError, 'Incompatible dimensions'
t, result_t = _commonType(a, b)
# lapack_routine = _findLapackRoutine('gesv', t)
lapack_routine = lapack_lite.zgesv
lapack_routine = lapack_lite.dgesv
a, b = _fastCopyAndTranspose(t, a, b)
pivots = zeros(n_eq, fortran_int)
results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)
if results['info'] > 0:
raise LinAlgError, 'Singular matrix'
If this isn't enough, you may want to look at the whole file yourself.
On Wed, Nov 19, 2008 at 7:14 AM, Alan G Isaac <firstname.lastname@example.org> wrote:
> If if look at help(np.linalg.solve) I am
> told what it does but not how it does it.
> If I look at
> there is even less info. I'll guess the
> algorithm is Gaussian elimination, but how
> would I use the documentation to confirm this?
> (Shouldn't I be able to?)
> I don't think possible differences from the "lite"
> version are a reason for saying nothing...
> Alan Isaac
> Numpy-discussion mailing list
More information about the Numpy-discussion