(arrays)
hstack that supports sparse and dense arrays

    If all arrays are dense, result is dense. Otherwise,
    result is a sparse (csc) array.
hstack that supports sparse and dense arrays
hstack that supports sparse and dense arrays
def hstack(arrays):
    """hstack that supports sparse and dense arrays

    If all arrays are dense, result is dense. Otherwise,
    result is a sparse (csc) array.
    """
    if any(sp.issparse(arr) for arr in arrays):
        arrays = [sp.csc_matrix(arr) for arr in arrays]
        return sp.hstack(arrays)
    else:
        return np.hstack(arrays)
def hstack ( arrays ) : if any ( sp . issparse ( arr ) for arr in arrays ) : arrays = [ sp . csc_matrix ( arr ) for arr in arrays ] return sp . hstack ( arrays ) else : return np . hstack ( arrays )