(arrays)
vstack that supports sparse and dense arrays

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

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