示例#1
0
    def _hstack(self, Xs):
        """Stacks Xs horizontally.

        This allows subclasses to control the stacking behavior, while reusing
        everything else from ColumnTransformer.

        Parameters
        ----------
        Xs : list of {array-like, sparse matrix, dataframe}
        """
        if self.sparse_output_:
            try:
                # since all columns should be numeric before stacking them
                # in a sparse matrix, `check_array` is used for the
                # dtype conversion if necessary.
                converted_Xs = [
                    check_array(X, accept_sparse=True, force_all_finite=False)
                    for X in Xs
                ]
            except ValueError as e:
                raise ValueError(
                    "For a sparse output, all columns should "
                    "be a numeric or convertible to a numeric.") from e

            return cu_sparse.hstack(converted_Xs).tocsr()
        else:
            Xs = [f.toarray() if issparse(f) else f for f in Xs]
            return np.hstack(Xs)
示例#2
0
 def _concat_cupy_sparse(L, axis=0):
     if axis == 0:
         return vstack(L)
     elif axis == 1:
         return hstack(L)
     else:
         msg = ("Can only concatenate cupy sparse matrices for axis in "
                "{0, 1}.  Got %s" % axis)
         raise ValueError(msg)