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..

Recommended Answers

All 2 Replies

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.