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 8957751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:03:46+00:00 2026-06-15T15:03:46+00:00

I need to hold a 50,000×50,000 sparse matrix/2d-array, with ~5% of the cells, uniformly

  • 0

I need to hold a 50,000×50,000 sparse matrix/2d-array, with ~5% of the cells, uniformly distributed, being non-empty. I will need to:

edit I need to do this in numpy/scipy, sorry if wasn’t clear. Also, added requirements.

  1. Read the 5% non-empty data from a DB, and assign it to matrix/2d-array cells, as quickly as possible.
  2. Use as little memory as possible.
  3. Use fancy indexing (take the indexes of and all non-empty values in a column, say). This is nice-to-have, memory and construction-time as more important.
  4. Once constructed, the matrix will not change.
  5. I will, however, want to take its transpose, with preferably O(1) memory and time.

What’s the most efficient way of achieving this?
Can I hold nan’s instead of zeros to indicate “empty” cells? (0 is a valid value for me), and can I efficiently run nansum, nanmean?
If not, can I efficiently take the index of and values of all non-zeros in a given column/row?

  • 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-06-15T15:03:47+00:00Added an answer on June 15, 2026 at 3:03 pm

    Well, for my purposes it seems like csc is the way to go. With 5% “sparsity factor”, the memory that the row indexes in csc take is still worth it. Here’s the code I used to test that the stuff I need really is fast:

    def build_csc(N, SPARSITY_FACTOR):
    
        data = []
        row_indexes = []
        column_indexes = [0] * (N+1)
    
        current_index = 0
        for j in xrange(N):
            column_indexes[j] = current_index
            for i in xrange(N):
                if random.random() < SPARSITY_FACTOR:
                    row_indexes.append(i)
                    data.append(random.random())
                    current_index += 1
        column_indexes[N] = current_index
    
        return sp.csc_matrix((data,row_indexes,column_indexes), shape=(N,N), dtype=np.float)
    
    
    def take_from_col(m, col_index):
        col = m[:,col_index]
        indexes = col.nonzero()[0]
        values = col[indexes]
    

    Running this in %timeit shows that this is indeed fast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Will there normally only be one instance of MainForm? I need to hold it
I need an array to hold member-function-pointers of different classes. How can I define
I need to hold an array of C strings. Now I know C strings
I need to hold a representation of a document in memory, and am looking
A simple question. I have a figure. I need to hold it, and put
I need a variable to hold results retrieved from the database. So far this
I know that table sources need a data source to hold the data that
I know they do not hold across pattern matches (i.e. you need to rewrite
Here is my predicament. Basically, I need a column in a table to hold
We need management 10,000 GPS devices, each GPS device upload a GPS data every

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.