当前位置: 首页>>代码示例>>Python>>正文


Python sparse.isspmatrix_lil方法代码示例

本文整理汇总了Python中scipy.sparse.isspmatrix_lil方法的典型用法代码示例。如果您正苦于以下问题:Python sparse.isspmatrix_lil方法的具体用法?Python sparse.isspmatrix_lil怎么用?Python sparse.isspmatrix_lil使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.sparse的用法示例。


在下文中一共展示了sparse.isspmatrix_lil方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sparse_remove_row

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import isspmatrix_lil [as 别名]
def sparse_remove_row(X, to_remove):
    """ Delete rows from a sparse matrix

    Parameters
    ----------
    X : scipy.sparse matrix
    to_remove : a list of row indices to be removed.

    Returns
    -------
    Y : scipy.sparse matrix
    """
    if not sps.isspmatrix_lil(X):
        X = X.tolil()

    to_keep = [i for i in iter(range(0, X.shape[0])) if i not in to_remove]
    Y = sps.vstack([X.getrowview(i) for i in to_keep])
    return Y 
开发者ID:kimjingu,项目名称:nonnegfac-python,代码行数:20,代码来源:matrix_utils.py

示例2: is_list_of_lil

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import isspmatrix_lil [as 别名]
def is_list_of_lil(z):
    return isinstance(z, list) and sparse.isspmatrix_lil(z[0]) 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:4,代码来源:lil.py

示例3: is_lil

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import isspmatrix_lil [as 别名]
def is_lil(z):
    return sparse.isspmatrix_lil(z) 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:4,代码来源:lil.py

示例4: _fix_connectivity

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import isspmatrix_lil [as 别名]
def _fix_connectivity(X, connectivity, affinity):
    """
    Fixes the connectivity matrix

        - copies it
        - makes it symmetric
        - converts it to LIL if necessary
        - completes it if necessary
    """
    n_samples = X.shape[0]
    if (connectivity.shape[0] != n_samples or
            connectivity.shape[1] != n_samples):
        raise ValueError('Wrong shape for connectivity matrix: %s '
                         'when X is %s' % (connectivity.shape, X.shape))

    # Make the connectivity matrix symmetric:
    connectivity = connectivity + connectivity.T

    # Convert connectivity matrix to LIL
    if not sparse.isspmatrix_lil(connectivity):
        if not sparse.isspmatrix(connectivity):
            connectivity = sparse.lil_matrix(connectivity)
        else:
            connectivity = connectivity.tolil()

    # Compute the number of nodes
    n_connected_components, labels = connected_components(connectivity)

    if n_connected_components > 1:
        warnings.warn("the number of connected components of the "
                      "connectivity matrix is %d > 1. Completing it to avoid "
                      "stopping the tree early." % n_connected_components,
                      stacklevel=2)
        # XXX: Can we do without completing the matrix?
        for i in range(n_connected_components):
            idx_i = np.where(labels == i)[0]
            Xi = X[idx_i]
            for j in range(i):
                idx_j = np.where(labels == j)[0]
                Xj = X[idx_j]
                D = pairwise_distances(Xi, Xj, metric=affinity)
                ii, jj = np.where(D == np.min(D))
                ii = ii[0]
                jj = jj[0]
                connectivity[idx_i[ii], idx_j[jj]] = True
                connectivity[idx_j[jj], idx_i[ii]] = True

    return connectivity, n_connected_components 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:50,代码来源:hierarchical.py

示例5: _fix_connectivity

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import isspmatrix_lil [as 别名]
def _fix_connectivity(X, connectivity, affinity):
    """
    Fixes the connectivity matrix

        - copies it
        - makes it symmetric
        - converts it to LIL if necessary
        - completes it if necessary
    """
    n_samples = X.shape[0]
    if (connectivity.shape[0] != n_samples or
            connectivity.shape[1] != n_samples):
        raise ValueError('Wrong shape for connectivity matrix: %s '
                         'when X is %s' % (connectivity.shape, X.shape))

    # Make the connectivity matrix symmetric:
    connectivity = connectivity + connectivity.T

    # Convert connectivity matrix to LIL
    if not sparse.isspmatrix_lil(connectivity):
        if not sparse.isspmatrix(connectivity):
            connectivity = sparse.lil_matrix(connectivity)
        else:
            connectivity = connectivity.tolil()

    # Compute the number of nodes
    n_components, labels = connected_components(connectivity)

    if n_components > 1:
        warnings.warn("the number of connected components of the "
                      "connectivity matrix is %d > 1. Completing it to avoid "
                      "stopping the tree early." % n_components,
                      stacklevel=2)
        # XXX: Can we do without completing the matrix?
        for i in xrange(n_components):
            idx_i = np.where(labels == i)[0]
            Xi = X[idx_i]
            for j in xrange(i):
                idx_j = np.where(labels == j)[0]
                Xj = X[idx_j]
                D = pairwise_distances(Xi, Xj, metric=affinity)
                ii, jj = np.where(D == np.min(D))
                ii = ii[0]
                jj = jj[0]
                connectivity[idx_i[ii], idx_j[jj]] = True
                connectivity[idx_j[jj], idx_i[ii]] = True

    return connectivity, n_components


###############################################################################
# Hierarchical tree building functions 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:54,代码来源:hierarchical.py


注:本文中的scipy.sparse.isspmatrix_lil方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。