fed*_*asu 6 python scipy sparse-matrix
好吧,我不认为,我可以用文字解释这个问题所以,这里是ipython会话的片段,我导入scipy,以构建一个稀疏矩阵.
In [1]: import scipy as sp
In [2]: a = sp.sparse.lil_matrix((5,5))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/liveuser/<ipython-input-2-b5a55fc2d0ac> in <module>()
----> 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
Out[6]:
<5x5 sparse matrix of type '<type 'numpy.float64'>'
with 0 stored elements in LInked List format>
In [7]: ax
Out[7]:
<5x5 sparse matrix of type '<type 'numpy.float64'>'
with 0 stored elements in LInked List format>
Run Code Online (Sandbox Code Playgroud)
那里发生了什么,为什么不能使用sp构造稀疏矩阵,在第一次,当我以特定方式导入稀疏子模块时(如在片段中),sp和spar变量现在都可用于构造稀疏矩阵.(我猜他们只是对同一个对象的引用)
我重现了这个python默认shell,(所以它不是ipython特定的)
发生了什么,是设计?如果那么精心制作.还是一个bug?
我的系统是Fedora 16 KDE-scientific,64位.
Fre*_*Foo 10
这是Python导入的工件,而不是SciPy的工件.做
from scipy import sparse [as sp]
Run Code Online (Sandbox Code Playgroud)
要么
import scipy.sparse [as sp]
Run Code Online (Sandbox Code Playgroud)
([]可选性的元符号在哪里).
简而言之,import语句需要知道模块的"真实"名称,而不是import as语句创建的某些缩写.
| 归档时间: |
|
| 查看次数: |
10263 次 |
| 最近记录: |