Results 1 to 4 of 4

Thread: Import csrtodense and densetocsr function from SciPy module

  1. #1
    Join Date
    Aug 2009
    Posts
    58

    Import csrtodense and densetocsr function from SciPy module

    Hello, I am a beginner with Python. How do I import and use the functions csrtodense and densetocsr contained in SciPy.sparse.sparsetools?

    To import sparsetools use
    Code:
    from scipy.sparse import sparsetools
    But to use the functions? I tried with:
    Code:
    scipy.sparse.sparsetools.densetocsr (M)
    (M is a matrix), but I get:
    Traceback (most recent call last):
    File "gcm.py", line 43, in <module>
    scipy.sparse.sparsetools.densetocsr (M)
    NameError: name 'SciPy' is not defined
    Any idea?

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Import csrtodense and densetocsr function from SciPy module

    I am not familiar with Python, and so I would not want to give a silly comment or reasons for your problem. But I think if I treat your functions in same manner as Java and C# Import then according to me, you must instantiate the class before using the methods. Did you tried this method, what happened in your case?

  3. #3
    Join Date
    Aug 2009
    Posts
    58

    Re: Import csrtodense and densetocsr function from SciPy module

    For example, to use the amount the cosine function with math module
    Code:
    import math
    then write
    Code:
    Math.cos (x)
    I thought it was worth the same for csrtodense and densetocsr and then I wrote for analogy. But now I realized that if you import only the cosine function with
    Code:
    from math import cos
    and I use
    Code:
    cos (x)
    Then, applying what you said, I tried
    Code:
    from scipy.sparse import sparsetools
    and wrote:
    Code:
    sparsetools.densetocsr (M)
    I got:
    Traceback (most recent call last):
    File "gcm.py", line 43, in <module>
    sparsetools.densetocsr(M)
    AttributeError: 'module' object has no attribute 'densetocsr'
    I'm going crazy

  4. #4
    Join Date
    Nov 2008
    Posts
    1,221

    Re: Import csrtodense and densetocsr function from SciPy module

    If you use the method from / import, then you must not precede the name of the library.

    So for example if you use the "import math" you need to use Math.cos (); but if you use "from math import cos" then you only need to use cos () without the "math." in front.

Similar Threads

  1. Replies: 7
    Last Post: 11-01-2014, 06:52 PM
  2. Replies: 5
    Last Post: 08-10-2011, 04:08 PM
  3. "Magic Fill import function" in Maxthon 3
    By Dum in forum Technology & Internet
    Replies: 5
    Last Post: 04-07-2011, 07:19 PM
  4. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  5. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,964,616.08584 seconds with 17 queries