I have the following matrices:
A.toarray()
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=int64)
type(A)
scipy.sparse.csr.csr_matrix
A.shape
(878049, 942)
And matrix B:
B
array([2248, 2248, 2248, ..., 0, 0, 0])
type(B)
numpy.ndarray
B.shape
(878049,)
I would like to column stack A
and B
in C, I tried the folowing:
C = sparse.column_stack([A,B])
Then:
/usr/local/lib/python3.5/site-packages/numpy/lib/shape_base.py in column_stack(tup)
315 arr = array(arr, copy=False, subok=True, ndmin=2).T
316 arrays.append(arr)
--> 317 return _nx.concatenate(arrays, 1)
318
319 def dstack(tup):
ValueError: all the input array dimensions except for the concatenation axis must match exactly
My problem is how can I preserve the dimentions. Thus, any idea of how to column stack them?.
Update
I tried the following:
#Sorry for the name
C = np.vstack(( A.A.T, B)).T
and I got:
array([[ 0, 0, 0, ..., 0, 6],
[ 0, 0, 0, ..., 0, 6],
[ 0, 0, 0, ..., 0, 6],
...,
[ 0, 0, 0, ..., 0, 1],
[ 0, 0, 0, ..., 0, 1],
[ 0, 0, 0, ..., 0, 1]], dtype=int64)
Is this the correct way to column stack them?.