def _compressed_sparse_stack(blocks, axis):
 other_axis = (1 if (axis == 0) else 0)
 data = np.concatenate([b.data for b in blocks])
 indices = np.concatenate([b.indices for b in blocks])
 indptr = []
 last_indptr = 0
 constant_dim = blocks[0].shape[other_axis]
 sum_dim = 0
 for b in blocks:
  if (b.shape[other_axis] != constant_dim):
   raise ValueError(('incompatible dimensions for axis %d' % other_axis))
  sum_dim += b.shape[axis]
  indptr.append((b.indptr[:(-1)] + last_indptr))
  last_indptr += b.indptr[(-1)]
 indptr.append([last_indptr])
 indptr = np.concatenate(indptr)
 if (axis == 0):
  return csr_matrix((data, indices, indptr), shape=(sum_dim, constant_dim))
 else:
  return csc_matrix((data, indices, indptr), shape=(constant_dim, sum_dim))

def _compressed_sparse_stack ( blocks , axis ) : other_axis = ( 1 if ( axis == 0 ) else 0 ) data = np . concatenate ( [ b . data for b in blocks ] ) indices = np . concatenate ( [ b . indices for b in blocks ] ) indptr = [ ] last_indptr = 0 constant_dim = blocks [ 0 ] . shape [ other_axis ] sum_dim = 0 for b in blocks : if ( b . shape [ other_axis ] != constant_dim ) : raise ValueError ( ( 'incompatible dimensions for axis %d' % other_axis ) ) sum_dim += b . shape [ axis ] indptr . append ( ( b . indptr [ : ( - 1 ) ] + last_indptr ) ) last_indptr += b . indptr [ ( - 1 ) ] indptr . append ( [ last_indptr ] ) indptr = np . concatenate ( indptr ) if ( axis == 0 ) : return csr_matrix ( ( data , indices , indptr ) , shape = ( sum_dim , constant_dim ) ) else : return csc_matrix ( ( data , indices , indptr ) , shape = ( constant_dim , sum_dim ) )
stacking fast path for csr/csc matrices (i) vstack for csr .