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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:27:53+00:00 2026-06-08T17:27:53+00:00

I got some sparse matrix like this >>>import numpy as np >>>from scipy.sparse import

  • 0

I got some sparse matrix like this

>>>import numpy as np
>>>from scipy.sparse import *
>>>A = csr_matrix((np.identity(3)))

>>>print A
  (0, 0)    1.0
  (1, 1)    1.0
  (2, 2)    1.0

For better understanding A is something like this:

>>>print A.todense()
[[ 1.  0.  0.]
 [ 0.  1.  0.]
 [ 0.  0.  1.]]

And I would like to have an operator (let us call it op1(n) ) doing this:

>>>A.op1(1)
[[ 0.  1.  0.]
 [ 0.  0.  1.]
 [ 1.  0.  0.]]

=> makes the last n columns the first n ones,
so

>>>A == A.op1(3)  
true

. Is there some build-in solution, (EDIT:) that returns a sparse matrix again?
The solution with roll:

X = np.roll(X.todense(),-tau, axis = 0)
print X.__class__

returns

<class 'numpy.matrixlib.defmatrix.matrix'>
  • 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-08T17:27:55+00:00Added an answer on June 8, 2026 at 5:27 pm

    scipy.sparse doesn’t have roll, but you can simulate it with hstack:

    from scipy.sparse import *
    A = eye(3, 3, format='csr')
    hstack((A[:, 1:], A[:, :1]), format='csr')    # roll left
    hstack((A[:, -1:], A[:, :-1]), format='csr')  # roll right
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
Got some C code I'm working on, and it looks like it should work.
Got some code which loads an input box, and then below this is an
I got some sample code for android.nfc.NfcSecureElement but it throws some error. The import
I got some help with this earlier today but I cannot figure out the
I got some problems with this query i need all my selectors but i
I got some help with gettin the number of rows returned from mysql, and
I got some funny but annoying problem. Somehow I toggled this kind of view
I got some html formatted in the following way: [Title|<a class=external href=http://test.com>http://test.com</a>] From these
Got some code here that isn't working: $(#sidebar ul li:last).each(function(){ $(this).addClass(last); }); Basically I

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.