Why can't I use scipy.io?

I'm trying to get started with scipy, but the package gives me some problems. The tutorial relies heavily on scipy.io, but when I import scypi and try to use scipy.io, I get errors:

In [1]: import scipy In [2]: help(scipy.io) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/chris/dev/scipy/<ipython-input-2-ef060398b31c> in <module>() ----> 1 help(scipy.io) AttributeError: 'module' object has no attribute 'io' 

I ran system updates and I uninstalled scipy and then installed it again.

Interestingly, I can import the module as follows:

 In [1]: import scipy.io 

But then when I try to use it, I get an error message as soon as I use the method:

 In [2]: arr = scipy.array([[1.0,2.0],[3.0,4.0],[5.0,6.0]]) In [3]: outFile = file('tmpdata1.txt', 'w') In [4]: scipy.io.write_array(outFile, arr) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /home/chris/dev/scipy/<ipython-input-4-46d22e4ff485> in <module>() ----> 1 scipy.io.write_array(outFile, arr) AttributeError: 'module' object has no attribute 'write_array' 

I am sure that I have something awkward, but I could not find the answer to this problem in Google or in the stackoverflow archives.

+7
source share
1 answer

Two things are here. Firstly, you cannot access the module in the package at all by doing import package , and then trying to access package.module . You often have to do what you did, import package.module or (if you don't want to type package.module all the time, you can do from package import module . That way you can also do from scipy import io .

Secondly, the scipy.io module scipy.io not provide the write_array function. It looks like it may have been wont, but they got rid of it. You might be looking at an outdated tutorial. (In which tutorial are you using?) Googling around, they seem to suggest using the numpy savetxt function, so you might want to explore this.

+15
source

All Articles