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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:42:44+00:00 2026-05-23T21:42:44+00:00

I am new to Python, so forgive me ahead of time if this is

  • 0

I am new to Python, so forgive me ahead of time if this is an elementary question, but I have searched around and have not found a satisfying answer.

I am trying to do the following using NumPy and SciPy:

I,J = x[:,0], x[:1]               # x is a two column array of (r,c) pairs
V = ones(len(I))
G = sparse.coo_matrix((V,(I,J)))  # G's dimensions are 1032570x1032570
G = G + transpose(G)
r,c = G.nonzero()
G[r,c] = 1
...
NotImplementedError: Fancy indexing in assignment not supported for csr matrices

Pretty much, I want all the nonzero values to equal 1 after adding the transpose, but I get the fancy indexing error messages.

Alternatively, if I could show that the matrix G is symmetric, adding the transpose would not be necessary.

Any insight into either approach would be very much appreciated.

  • 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-23T21:42:45+00:00Added an answer on May 23, 2026 at 9:42 pm

    In addition to doing something like G = G / G, you can operate on G.data.

    So, in your case, doing either:

    G.data  = np.ones(G.nnz)
    

    or

    G.data[G.data != 0] = 1
    

    Will do what you want. This is more flexible, as it allows you to preform other types of filters (e.g. G.data[G.data > 0.9] = 1 or G.data = np.random.random(G.nnz))

    The second option will only set the values to one if they have a nonzero value. During some calculations, you’ll wind up with zero values that are “dense” (i.e. they’re actually stored as a value in the sparse array). (You can remove these in-place with G.eliminate_zeros())

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

Sidebar

Related Questions

I'm new to Python so forgive me if this is basic, I've searched but
I'm relatively new to wxPython (but not Python itself), so forgive me if I've
Fairly new to python, forgive me if this is a basic question about learning
Firstly, I'm new to Python, Qt and PySide so forgive me if this question
I am very new to Python, so forgive me if this question is very
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I am very new to python and have no idea what I'm doing but
I'm new to Python so forgive my ignorance If I don't have all the
I am new to Django and Python, please forgive me if this is a
I am new to machine learning in python, therefore forgive my naive question. Is

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.