Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.linalg.inv

numpy.linalg.inv(a)[source]

Compute the (multiplicative) inverse of a matrix.

Given a square matrixa, return the matrixainv satisfyingdot(a,ainv)=dot(ainv,a)=eye(a.shape[0]).

Parameters:

a : (..., M, M) array_like

Matrix to be inverted.

Returns:

ainv : (..., M, M) ndarray or matrix

(Multiplicative) inverse of the matrixa.

Raises:

LinAlgError

Ifa is not square or inversion fails.

Notes

New in version 1.8.0.

Broadcasting rules apply, see thenumpy.linalg documentation fordetails.

Examples

>>>fromnumpy.linalgimportinv>>>a=np.array([[1.,2.],[3.,4.]])>>>ainv=inv(a)>>>np.allclose(np.dot(a,ainv),np.eye(2))True>>>np.allclose(np.dot(ainv,a),np.eye(2))True

If a is a matrix object, then the return value is a matrix as well:

>>>ainv=inv(np.matrix(a))>>>ainvmatrix([[-2. ,  1. ],        [ 1.5, -0.5]])

Inverses of several matrices can be computed at once:

>>>a=np.array([[[1.,2.],[3.,4.]],[[1,3],[3,5]]])>>>inv(a)array([[[-2. ,  1. ],        [ 1.5, -0.5]],       [[-5. ,  2. ],        [ 3. , -1. ]]])

Previous topic

numpy.linalg.lstsq

Next topic

numpy.linalg.pinv

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp