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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:33:41+00:00 2026-06-11T11:33:41+00:00

You have an original sparse matrix X: >>print type(X) >>print X.todense() <class ‘scipy.sparse.csr.csr_matrix’> [[1,4,3]

  • 0

You have an original sparse matrix X:

>>print type(X) 
>>print X.todense()
<class 'scipy.sparse.csr.csr_matrix'>
[[1,4,3]
 [3,4,1]
 [2,1,1]
 [3,6,3]]

You have a second sparse matrix Z, which is derived from some rows of X (say the values are doubled so we can see the difference between the two matrices). In pseudo-code:

>>Z = X[[0,2,3]]
>>print Z.todense()
[[1,4,3]
 [2,1,1]
 [3,6,3]]

>>Z = Z*2
>>print Z.todense()
[[2, 8, 6]
 [4, 2, 2]
 [6, 12,6]]

What’s the best way of retrieving the rows in Z using the ORIGINAL indices from X. So for instance, in pseudo-code:

>>print Z[[0,3]]
[[2,8,6]              #0 from Z, and what would be row **0** from X)
 [6,12,6]]            #2 from Z, but what would be row **3** from X)

That is, how can you retrieve rows from Z, using indices that refer to the original rows position in the original matrix X? To do this, you can’t modify X in anyway (you can’t add an index column to the matrix X), but there are no other limits.

  • 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-11T11:33:42+00:00Added an answer on June 11, 2026 at 11:33 am

    If you have the original indices in an array i, and the values in i are in increasing order (as in your example), you can use numpy.searchsorted(i, [0, 3]) to find the indices in Z that correspond to indices [0, 3] in the original X. Here’s a demonstration in an IPython session:

    In [39]: X = csr_matrix([[1,4,3],[3,4,1],[2,1,1],[3,6,3]])
    
    In [40]: X.todense()
    Out[40]: 
    matrix([[1, 4, 3],
            [3, 4, 1],
            [2, 1, 1],
            [3, 6, 3]])
    
    In [41]: i = array([0, 2, 3])
    
    In [42]: Z = 2 * X[i]
    
    In [43]: Z.todense()
    Out[43]: 
    matrix([[ 2,  8,  6],
            [ 4,  2,  2],
            [ 6, 12,  6]])
    
    In [44]: Zsub = Z[searchsorted(i, [0, 3])]
    
    In [45]: Zsub.todense()
    Out[45]: 
    matrix([[ 2,  8,  6],
            [ 6, 12,  6]])
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an original NSData type which contains let's say 100 bytes. I want
I am writing a sparse matrix class. I need to have a node class,
[Original] I have a ListBox which has its ItemsSource (this is done in the
I have a php script which saves the original image, then resizes it -
I have a service named WcfService2 (original i know) which has an IService.cs file
I have a sparse matrix that is not symmetric I.E. the sparsity is somewhat
I have made a List of Lists implementation of a sparse matrix, and I've
I have one original object post.rb with the next fields or attributes. class Post
I have this original formula from a medical research book: Log(e) (EFW) = (-4.564+(0.282*AC)-(0.00331*AC^2))*1000
Let's say I have some original text: here is some text that has a

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.