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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 340k
  • Answers 340k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer IE6 and IE7 definitely don't pass through the value of… May 14, 2026 at 4:44 am
  • Editorial Team
    Editorial Team added an answer I had a look through the pg_* tables, and I… May 14, 2026 at 4:44 am
  • Editorial Team
    Editorial Team added an answer Ok guys worked out the issue and its incredibly simple… May 14, 2026 at 4:44 am

Related Questions

I have a CSV file which I am processing and putting the processed data
This is a C# problem. I have a big object in memory at a
I have written an ASP.NET web page with C# behind that runs an existing
I've a database table of timesheets with some common feilds. id, client_id, project_id, task_id,
Scenario: I load some data into a local MySQL database each day, about 2

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.