zoukankan      html  css  js  c++  java
  • csr_matrix参数解析

    压缩稀疏矩阵构造时的参数从官网看不明白,参考如下:


     

    
    
    >>> indptr = np.array([0, 2, 3, 6])
    >>> indices = np.array([0, 2, 2, 0, 1, 2])
    >>> data = np.array([1, 2, 3, 4, 5, 6])
    >>> csr_matrix((data, indices, indptr), shape=(3, 3)).toarray()
    array([[1, 0, 2],
           [0, 0, 3],
           [4, 5, 6]])
    (注:论文的行下标和列下标均从0开始)

     

    data 表示 元数据 显然为1, 2, 3, 4, 5, 6

    shape 表示 矩阵的形状 为 3 * 3

    indices 表示 各个数据在各行的下标, 从该数据我们可以知道:数据1在某行的0位置处, 数据2在某行的2位置处,6在某行的2位置处。

    而各个数据在哪一行就要通过indptr参数得到的

    indptr 表示每行数据的个数:[0 2 3 6]表示从第0行开始数据的个数,0表示默认起始点,0之后有几个数字就表示有几行,第一个数字2表示第一行有2 - 0 = 2个数字,因而数字1,2都第0行,第二行有3 - 2 = 1个数字,因而数字3在第1行,以此类推,我们能够知道所有数字的行号

    Example: 数字6 ,indptr推出在第2行,indices推出在第2列。

  • 相关阅读:
    浅谈聚类算法(K-means)
    多步法求解微分方程数值解
    本学期微分方程数值解课程总结(matlab代码)
    Stone Game
    Two Sum IV
    Insert into a Binary Search Tree
    Subtree of Another Tree
    Leaf-Similar Trees
    Diameter of Binary Tree
    Counting Bits
  • 原文地址:https://www.cnblogs.com/Rvin/p/10062554.html
Copyright © 2011-2022 走看看