5
好吧,我不認爲,我可以用單詞解釋這個問題,所以,這裏是ipython會話的片段,我在這裏輸入scipy,以便構造一個稀疏矩陣。在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>
正在發生的事情有,爲什麼不能使用SP構建一個稀疏矩陣,在第一時間,當我在一個特定的方式導入稀疏子模塊(如片段),SP和晶石變量現在可以用來構建稀疏矩陣。(我猜他們只是引用同一個對象)
我轉載這條巨蟒默認的shell,(所以它不是IPython的具體)
這是怎麼回事,是它通過設計??如果這麼親切地闡述。或者它是一個錯誤?
我的系統是Fedora 16 KDE-scientific,64位。
不,我正在導入總scipy作爲sp,我希望從代碼段清楚。你的意思是當我導入scipy作爲sp,稀疏子模塊不導入,因爲它是可選的? – fedvasu 2012-01-04 14:53:10
@fedvasu:無論您如何導入scipy,都不會導入'sparse'。您必須明確導入並使用其全名。 – 2012-01-04 14:53:53
爲什麼這樣? ,你能否在這裏澄清一點:http://chat.stackoverflow.com/rooms/6384/quickscipy-talk – fedvasu 2012-01-04 14:56:11