What is wrong with importing modules in scipy , is it a bug?

This is an artifact of Python's importing, not of SciPy. Do.

Up vote 0 down vote favorite share g+ share fb share tw.

Ok , I don't think, I can explain this problem in words so , here is the snippet of ipython session , where I import scipy , in order to construct a sparse matrix. In 1: import scipy as sp In 2: a = sp.sparse. Lil_matrix((5,5)) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/liveuser/ in () ----> 1 a = sp.sparse.

Lil_matrix((5,5)) AttributeError: 'module' object has no attribute 'sparse' In 3: import scipy. Sparse as spar In 4: ax = spar. Lil_matrix((5,5)) In 5: a = sp.sparse.

Lil_matrix((5,5)) # you are kidding me? In 6: a Out6: ' with 0 stored elements in LInked List format> In 7: ax Out7: ' with 0 stored elements in LInked List format> what is happening there , why can't construct a sparse matrix using sp , in the first time , when I import sparse sub-module in a particular way (as in snippet) , both sp and spar variables can now be used to construct sparse matrices.(i guess they are just references to same object) I reproduced this python default shell , (so it is not ipython specific) what's going on , is it by design? If so kindly elaborate.

Or is it a bug? My system is Fedora 16 KDE-scientific,64 bit. Python scipy sparse link|improve this question edited Jan 4 at 14:50larsmans71.4k761133 asked Jan 4 at 14:47fedvasu19311 85% accept rate.

This is an artifact of Python's importing, not of SciPy. Do from scipy import sparse as sp or import scipy. Sparse as sp (where is meta-notation for optionality).

In short, the import statement needs to know the module's "true" name, not some abbreviation created by an import as statement.

No , i'm importing total scipy as sp , I hope thats clear from the code snippet. Do you mean when I import scipy as sp ,sparse sub-module is not imported as it is optional? – fedvasu Jan 4 at 14:53 @fedvasu: sparse is not imported when you import scipy, regardless of how you import it.

You must import it explicitly and use its full name. – larsmans Jan 4 at 14:53 why so? , could you clarify that point here chat.stackoverflow.com/rooms/6384/quicks... – fedvasu Jan 4 at 14:56 3 It's just not.

The subpackages of scipy do not get imported by import scipy by design. It is intended that you import them separately. Never use a plain import scipy; there's no point.

Once you do import them separately, Python inserts the subpackage module objects into the scipy namespace. It's just how the Python import mechanism works. – Robert Kern Jan 4 at 14:58 you nailed it!

– fedvasu Jan 4 at 15:02.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions