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

  • Home
  • SEARCH
  • 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 8205431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:14:14+00:00 2026-06-07T08:14:14+00:00

I am using scipy’s weave.inline to perform computationally expensive tasks. I have problems returning

  • 0

I am using scipy’s weave.inline to perform computationally expensive tasks. I have problems returning an one-dimensional array back into the python scope. Weave.inline uses a special argument called “return_val” for the purpose of returning values back into the python scope.
The following example returning an integer value works well:

>>> from scipy.weave import inline
>>> print inline(r'''int N = 10; return_val = N;''')
10

However the following example, which indeed compiles without prompting an error, does not return the array i would expect:

>>> from scipy.weave import inline
>>> code =\
    r'''                                                              
       int* pairs;                                                       
       int  lenght = 0;                                                      
       for (int i=0;i<N;i++){                                            
         lenght   += 1;                                                     
         pairs     = (int *)malloc(sizeof(int)*lenght);                       
         pairs[i]  = i;
         std::cout << pairs[i] << std::endl;              
       }                                                                 
       return_val = pairs;                                               
    '''
 >>> N  = 5
 >>> R = inline(code,['N'])
 >>> print "RETURN_VAL:",R
 0
 1
 2
 3
 4
 RETURN_VAL: 1    

I need to reallocate the size of the array “pairs” dynamically which is why I can’t pass a numpy.array or python list per se.

  • 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-07T08:14:15+00:00Added an answer on June 7, 2026 at 8:14 am

    All you need to do is use the raw python c-api calls, or if you’re looking for something a bit more convenient, the built in scipy weave wrappers.

    No guarantees about leaks or efficiency, but it should look something a bit like this:

    from scipy.weave import inline
    
    code = r'''
        py::list ret; 
        for(int i = 0; i < N; i++) {
            py::list item;
            for(int j = 0; j < i; j++) {
                item.append(j);
            }
            ret.append(item);
        }
        return_val = ret;
        '''
    N  = 5 
    R = inline(code,['N'])
    print R
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using scipy.weave.inline. I want to program a unitstep function centered
I have been using the scipy.stats.invgamma.rvs function to randomly select values from an inverse
i am using this: http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html i have an list a that i want to
I have an 2 dimensional array. Each of the row vectors, in this case,
The scipy document gives examples of Blitz++ style operations when using weave.blitz() and C
Using SciPy and MATLAB, I'm having trouble reconstructing an array to match what is
I have scipy and numpy, Python v3.1 I need to create a 1D array
I am using scipy intensively for various purposes. I have noticed that the first
In numpy/scipy I have an image stored in an array. I can display it,
I have been trying to get the result of a lognormal distribution using Scipy

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.