[Tutor] Matrix Multiplication and its Inverse

Peter Otten __peter__ at web.de
Sat Jul 13 09:45:34 CEST 2013


Jack Little wrote:

> Is there a way in python to do matrix multiplication and its inverse? No
> external modules is preferred, but it is ok.

Use numpy:

>>> import numpy, numpy.linalg
>>> a = numpy.array([[1, 2], [3, 4]])
>>> b = numpy.linalg.inv(a)
>>> b
array([[-2. ,  1. ],
       [ 1.5, -0.5]])
>>> numpy.dot(a, b)
array([[ 1.,  0.],
       [ 0.,  1.]])




More information about the Tutor mailing list