scipy.sparse.hstack((1, [2]))
和scipy.sparse.hstack((1, [2]))
很好,但不是scipy.sparse.hstack(([1], [2]))
。爲什麼會這樣?scipy.sparse.hstack(([1],[2])) - >「ValueError:blocks must be 2-D」。爲什麼?
這裏是發生了什麼事我的系統上的跟蹤:
C:\Anaconda>python
Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 16:44:52) [MSC v.
1500 64 bit (AMD64)] on win32
>>> import scipy.sparse
>>> scipy.sparse.hstack((1, [2]))
<1x2 sparse matrix of type '<type 'numpy.int32'>'
with 2 stored elements in COOrdinate format>
>>> scipy.sparse.hstack((1, 2))
<1x2 sparse matrix of type '<type 'numpy.int32'>'
with 2 stored elements in COOrdinate format>
>>> scipy.sparse.hstack(([1], [2]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\site-packages\scipy\sparse\construct.py", line 456, in h
stack
return bmat([blocks], format=format, dtype=dtype)
File "C:\Anaconda\lib\site-packages\scipy\sparse\construct.py", line 539, in b
mat
raise ValueError('blocks must be 2-D')
ValueError: blocks must be 2-D
>>> scipy.version.full_version
'0.16.0'
>>>
我想你的意思是'hstack(([1],2))'起作用。 – hpaulj
@hpaulj謝謝,修復! –
我們有沒有回答你的問題? – rayryeng