0

I thought that the code in the python-inverse-of-a-matrix was extremely interesting, particularly since I have used numpy for several years in computations that involve matrices. I was disappointed as the 2 imports from numpy failed. Here are the imports:

from numpy import matrix
from numpy import linalg

Neither matrix nor linalg were found in the numpy package. Clearly I miss something that is quite obvious (not for me, though :) ).

I use Linux (kubuntu) and downloaded the numpy package as a debian package. Are there other packages for "matrix" and for "linalg", if so, what are they?

Thank you in anticipation,

OldAl.

Amro
  • 123,847
  • 25
  • 243
  • 454
user377367
  • 119
  • 1
  • 2

2 Answers2

4

Most likely, you have a numpy.py or numpy.pyc file in your local directory... and python is finding it and importing it instead of the numpy package you expect.

Try this before importing.

import numpy
print(numpy.__file__)

You'll probably find that numpy.__file__ is pointing not to the numpy package, but to something you did not intend to import.

In general, it's a good idea to name your own modules with different names from known/popular packages.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
Jason R. Coombs
  • 41,115
  • 10
  • 83
  • 93
  • Actually, numpy is imported and works correctly. Has for the last 5 years... The deb package numpy simply does not have the matrix and linalg sub-packages. In ubuntu or kubuntu one needs to import scipy as well. Scipy expands the name space of numpy and adds matrix and linalg packages and more. Thanks for you contribution! OldAl. – user377367 Jun 27 '10 at 20:56
  • OldAl - since you found your answer, I suggest you answer you own question, then mark it as the correct answer. – Jason R. Coombs Jun 28 '10 at 11:25
0

SOLVED The deb package numpy simply does not have the matrix and linalg sub-packages.

In ubuntu or kubuntu one needs to import scipy as well. Scipy expands the name space of numpy and adds matrix and linalg packages. OldAl.