zoukankan      html  css  js  c++  java
  • csr_matrix


    from scipy.sparse import *

    row = [0,0,0,1,1,1,2,2,2]#行指标
    col = [0,1,2,0,1,2,0,1,2]#列指标
    data = [1,0,1,0,1,1,1,1,0]#在行指标列指标下的数字
    team = csr_matrix((data,(row,col)),shape=(3,3))
    print(team)
    print(team.todense())


    输出结果:
    (0, 0) 1
    (0, 1) 0
    (0, 2) 1
    (1, 0) 0
    (1, 1) 1
    (1, 2) 1
    (2, 0) 1
    (2, 1) 1
    (2, 2) 0
    [[1 0 1]
    [0 1 1]
    [1 1 0]]

    Process finished with exit code 0
    row = [0,0,0,0,1,1,1,1,2,2,2,2]#行指标
    col = [0,1,2,3,0,1,2,3,0,1,2,3]#列指标
    data = [1,0,1,1,0,1,1,1,1,0,1,1]#在行指标列指标下的数字
    team = csr_matrix((data,(row,col)),shape=(3,4))
    # print(team)
    # print(team.todense())
    team_dok = team.todok()
    # print(team_dok)

    team_coo = team_dok.tocoo()
    item =list(team_coo.col.reshape(-1))
    # print(type(item))
    print(item)


    输出:
    [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]
    team_coo = team_dok.tocoo()
    item =list(team_coo.col.reshape(-1))
    user =list(team_coo.row.reshape(-1))
    print("col:",item)
    print("row:",user)

    输出:
    col: [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]
    row: [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]

    Process finished with exit code 0

    ————————————————
    版权声明:本文为CSDN博主「DBL_fish」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_41853536/article/details/83345273

  • 相关阅读:
    PL/SQL 入门
    Nginx 安装和配置
    MySql 优化方案
    类加载器(ClassLoader)
    动态代理入门
    Servlet 3.0 介绍
    反射加强(一)
    Python(1)—is和==区别
    代码题(10)— 验证二叉搜索树、二叉搜索树的最近公共祖先
    代码题(9)— 二叉树的最大、最小深度、平衡二叉树
  • 原文地址:https://www.cnblogs.com/lkl7117/p/11660426.html
Copyright © 2011-2022 走看看