MCPcopy Create free account
hub / github.com/numpy/numpy / solve

Function solve

numpy/linalg/linalg.py:330–411  ·  view source on GitHub ↗

Solve a linear matrix equation, or system of linear scalar equations. Computes the "exact" solution, `x`, of the well-determined, i.e., full rank, linear matrix equation `ax = b`. Parameters ---------- a : (..., M, M) array_like Coefficient matrix. b : {(..., M

(a, b)

Source from the content-addressed store, hash-verified

328
329@array_function_dispatch(_solve_dispatcher)
330def solve(a, b):
331 """
332 Solve a linear matrix equation, or system of linear scalar equations.
333
334 Computes the "exact" solution, `x`, of the well-determined, i.e., full
335 rank, linear matrix equation `ax = b`.
336
337 Parameters
338 ----------
339 a : (..., M, M) array_like
340 Coefficient matrix.
341 b : {(..., M,), (..., M, K)}, array_like
342 Ordinate or "dependent variable" values.
343
344 Returns
345 -------
346 x : {(..., M,), (..., M, K)} ndarray
347 Solution to the system a x = b. Returned shape is identical to `b`.
348
349 Raises
350 ------
351 LinAlgError
352 If `a` is singular or not square.
353
354 See Also
355 --------
356 scipy.linalg.solve : Similar function in SciPy.
357
358 Notes
359 -----
360
361 .. versionadded:: 1.8.0
362
363 Broadcasting rules apply, see the `numpy.linalg` documentation for
364 details.
365
366 The solutions are computed using LAPACK routine ``_gesv``.
367
368 `a` must be square and of full-rank, i.e., all rows (or, equivalently,
369 columns) must be linearly independent; if either is not true, use
370 `lstsq` for the least-squares best "solution" of the
371 system/equation.
372
373 References
374 ----------
375 .. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando,
376 FL, Academic Press, Inc., 1980, pg. 22.
377
378 Examples
379 --------
380 Solve the system of equations ``x0 + 2 * x1 = 1`` and ``3 * x0 + 5 * x1 = 2``:
381
382 >>> a = np.array([[1, 2], [3, 5]])
383 >>> b = np.array([1, 2])
384 >>> x = np.linalg.solve(a, b)
385 >>> x
386 array([-1., 1.])
387

Callers 1

tensorsolveFunction · 0.70

Calls 8

_makearrayFunction · 0.85
_assert_stacked_2dFunction · 0.85
_assert_stacked_squareFunction · 0.85
_commonTypeFunction · 0.85
isComplexTypeFunction · 0.85
get_linalg_error_extobjFunction · 0.85
wrapFunction · 0.85
astypeMethod · 0.80

Tested by

no test coverage detected