0

Hello everyone.. I'm a new user of python.. I have encountered a problem while trying to find the inverse of a matrix even after importing numpy and scipy. The error is:

>>> a=[[[1, 2, 3],
[2, 3, 4],
[3, 4, 5]], float]
>>> print a
[[[1, 2, 3], [2, 3, 4], [3, 4, 5]], <type 'float'>]
>>> ai=inverse(a)

Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
ai=inverse(a)
NameError: name 'inverse' is not defined
>>> ai=numpy.inverse(a)

Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
ai=numpy.inverse(a)
AttributeError: 'module' object has no attribute 'inverse'

Please help..

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vegaseat
0

This works for me

import numpy
a=numpy.matrix([[1, 2, 3],
[2, 3, 4],
[3, 4, 5]], dtype=numpy.float)
print a
b  =  a ** (-1)
print b
print b * a
"""my output --->
[[ 1.  2.  3.]
 [ 2.  3.  4.]
 [ 3.  4.  5.]]
[[  4.50359963e+15  -9.00719925e+15   4.50359963e+15]
 [ -9.00719925e+15   1.80143985e+16  -9.00719925e+15]
 [  4.50359963e+15  -9.00719925e+15   4.50359963e+15]]
[[-4. -6. -8.]
 [ 8.  4.  0.]
 [-2.  0.  4.]]

Note that in fact the matrix a is not invertible because its rows are generated by the 2 vectors 1, 2, 3 and 1, 1, 1.
If you want a list of attributes to numpy or a, you can try

>>> import numpy
>>> dir(numpy)
....
>>> a = numpy.matrix(...) # or numpy.array
>>> help(a)

Also read a python tutorial if you're new to python :)

Edited by Gribouillis: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.