Note that there are some explanatory texts on larger screens.

plurals
  1. POCollecting results from a loop that returns NumPy Arrays
    primarykey
    data
    text
    <p>I'm an admittedly pretty basic Python programmer, trying to learn as I encounter problems implementing various research problems. And I've hit one of those problems - particularly, how to handle loops where I'm returning a bunch of data, rather than the usual "out comes a single number" examples where you just add the result of the loop to everything previous.</p> <p>Here's a Gist of the unlooped script I'm trying to run: <a href="https://gist.github.com/1390355" rel="noreferrer">https://gist.github.com/1390355</a></p> <p>The really salient point is the end of the model_solve function:</p> <pre><code>def model_solve(t): # lots of variables set params = np.zeroes((n_steps,n_params) params[:,0] = beta params[:,1] = gamma timer = np.arange(n_steps).reshape(n_steps,1) SIR = spi.odeint(eq_system, startPop, t_interval) output = np.hstack((timer,SIR,params)) return output </code></pre> <p>That returns the results of the ODE integration bit (<code>spi.odeint</code>) along with a simple "What time step are we on?" timer and essentially two columns of the value of two random variables repeated many, many times in the form of 4950 row and 7 column NumPy array.</p> <p>The goal however is to run a Monte Carlo analysis of the two parameters (beta and gamma) which have random values. Essentially, I want to make a function that loops somewhat like so:</p> <pre><code>def loop_function(runs): for i in range(runs): model_solve(100) # output of those model_solves collected here # return collected output </code></pre> <p>That collected output would then be written to a file. Normally, I'd just have each model_solve function write its results to a file, but this code is going to be run on <a href="http://www.picloud.com" rel="noreferrer">PiCloud</a> or another platform where I don't necessarily have the ability to write a file until the results are returned to the local machine. Instead, I'm trying to get a return of a huge NumPy array of <code>runs</code>*7 columns and 4950 rows - which can then be written to a file on my local machine.</p> <p>Any clues as to how to approach this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload