如果您有两个 numpy 矩阵,您如何将它们合并为一个?它们应该水平连接,这样
[[0] [1] [[0][1]
[1] + [0] = [1][0]
[4] [1] [4][1]
[0]] [1]] [0][1]]
例如,使用这些矩阵:
>>type(X)
>>type(Y)
>>X.shape
>>Y.shape
<class 'numpy.matrixlib.defmatrix.matrix'>
<class 'numpy.matrixlib.defmatrix.matrix'>
(53, 1)
(53, 1)
我试过 hstack 但得到一个错误:
>>Z = hstack([X,Y])
Traceback (most recent call last):
File "labels.py", line 85, in <module>
Z = hstack([X, Y])
File "C:\Python27\lib\site-packages\scipy\sparse\construct.py", line 263, in h
stack
return bmat([blocks], format=format, dtype=dtype)
File "C:\Python27\lib\site-packages\scipy\sparse\construct.py", line 329, in b
mat
raise ValueError('blocks must have rank 2')
ValueError: blocks must have rank 2