scipy.io导入问题 [英] import problems with scipy.io

查看:204
本文介绍了scipy.io导入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图开始使用scipy,但是该软件包给我带来了一些问题.本教程严重依赖scipy.io,但是当我导入scypi并尝试使用scipy.io时,出现错误:

I've been trying to get started with scipy, but the package is giving me some problems. The tutorial leans 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'

我已经运行了系统更新,并且先卸载了scipy,然后又重新安装了它.

I've run system updates and I uninstalled scipy then installed it again.

有趣的是,我可以这样导入模块:

Interestingly enough, I can import the module this way:

In [1]: import scipy.io

但是当我尝试使用它时,一旦使用一种方法,我会收到一条错误消息:

But then when I try to use it, I get an error as soon as I use a 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'

我确定我缺少令人尴尬的基本知识,但是我无法在Google或stackoverflow归档文件中找到此问题的答案.

I'm sure I'm missing something embarrassingly basic, but I've not been able to find an answer to this problem on Google or in the stackoverflow archives.

推荐答案

这里有两件事.首先,通常不能通过执行import package然后尝试访问package.module来访问程序包中的模块.通常,您必须做import package.module,或者(如果不想一直输入package.module,则可以执行from package import module.因此,您也可以执行from scipy import io.

Two things here. First, you cannot in general access a module in a package 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. So you can also do from scipy import io.

第二,scipy.io模块不提供write_array功能.看起来好像过去,但他们摆脱了它.您可能正在看一个过时的教程. (您正在使用什么教程?)四处搜寻,似乎他们建议改用numpy的savetxt函数,因此您可能需要研究一下.

Second, the scipy.io module does not provide a write_array function. It looks like maybe it used to, but they got rid of it. You may be looking at an outdated tutorial. (What tutorial are you using?) Googling around, it seems they suggest to use numpy's savetxt function instead, so you might want to look into that.

这篇关于scipy.io导入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆