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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:46:58+00:00 2026-05-26T11:46:58+00:00

For SciPy sparse matrix, one can use todense() or toarray() to transform to NumPy

  • 0

For SciPy sparse matrix, one can use todense() or toarray() to transform to NumPy matrix or array. What are the functions to do the inverse?

I searched, but got no idea what keywords should be the right hit.

  • 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-26T11:46:58+00:00Added an answer on May 26, 2026 at 11:46 am

    You can pass a numpy array or matrix as an argument when initializing a sparse matrix. For a CSR matrix, for example, you can do the following.

    >>> import numpy as np
    >>> from scipy import sparse
    >>> A = np.array([[1,2,0],[0,0,3],[1,0,4]])
    >>> B = np.matrix([[1,2,0],[0,0,3],[1,0,4]])
    
    >>> A
    array([[1, 2, 0],
           [0, 0, 3],
           [1, 0, 4]])
    
    >>> sA = sparse.csr_matrix(A)   # Here's the initialization of the sparse matrix.
    >>> sB = sparse.csr_matrix(B)
    
    >>> sA
    <3x3 sparse matrix of type '<type 'numpy.int32'>'
            with 5 stored elements in Compressed Sparse Row format>
    
    >>> print sA
      (0, 0)        1
      (0, 1)        2
      (1, 2)        3
      (2, 0)        1
      (2, 2)        4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I raise a scipy.sparse matrix to a power, element-wise? numpy.power should, according
I will have to implement a convolution of two functions in Python, but SciPy/Numpy
In numpy/scipy I have an image stored in an array. I can display it,
SciPy appears to provide most (but not all [1]) of NumPy's functions in its
I am trying to use scipy and numpy to perform matrix addition and multiplication.
given a list of module names (e.g. mymods = ['numpy', 'scipy', ...]) how can
I am using Scipy to construct a large, sparse (250k X 250k) co-occurrence matrix
How can I quickly extract two rows of a scipy.sparse.lil_matrix and apply bitwise operations
I'm trying to use the ndimage library from scipy, but its apparently missing. I
NumPy arrays can be indexed with an array of booleans to select the rows

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.