Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 533877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:33:14+00:00 2026-05-13T09:33:14+00:00

I have a big csv file which lists connections between nodes in a graph.

  • 0

I have a big csv file which lists connections between nodes in a graph. example:

0001,95784
0001,98743
0002,00082
0002,00091

So this means that node id 0001 is connected to node 95784 and 98743 and so on.
I need to read this into a sparse matrix in numpy. How can i do this?
I am new to python so tutorials on this would also help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:33:14+00:00Added an answer on May 13, 2026 at 9:33 am

    Example using lil_matrix (list of list matrix) of scipy.

    Row-based linked list matrix.

    This contains a list (self.rows) of rows, each of which is a sorted list of column indices of non-zero elements. It also contains a list (self.data) of lists of these elements.

    $ cat 1938894-simplified.csv
    0,32
    1,21
    1,23
    1,32
    2,23
    2,53
    2,82
    3,82
    4,46
    5,75
    7,86
    8,28
    

    Code:

    #!/usr/bin/env python
    
    import csv
    from scipy import sparse
    
    rows, columns = 10, 100
    matrix = sparse.lil_matrix( (rows, columns) )
    
    csvreader = csv.reader(open('1938894-simplified.csv'))
    for line in csvreader:
        row, column = map(int, line)
        matrix.data[row].append(column)
    
    print matrix.data
    

    Output:

    [[32] [21, 23, 32] [23, 53, 82] [82] [46] [75] [] [86] [28] []]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big string (let's call it a CSV file, though it isn't
I have a big lump of binary data in a char[] array which I
I have big issue with url-rewriting for IIS 7.0. I've written simple module for
How would you maintain the legacy applications that: Has no unit tests have big
i have a big web application running in perl CGI. It's running ok, it's
I have a big load of documents, text-files, that I want to search for
I have this big data-entry sort of page, a table kind of layout using
i have some big xslt crashing iis (StackOverflowException) when loading an XslCompiledTransform while the
I have a big red button and I'm trying to use javascript to perform
I have pretty big background of .net, and I've decided that i want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.