[SciPy-user] Newbie, deferring large array generation
lorenzo bolla
lbolla at gmail.com
Wed Mar 19 06:51:48 EDT 2008
you can maybe use xrange.
dx = (stop - start) / (very_big_num - 1)
xa = xrange(very_big_num)
for ia in xa:
a = ia * dx
use a...
hth.
L.
On Wed, Mar 19, 2008 at 10:42 AM, Joseph Anderson <J.Anderson at hull.ac.uk>
wrote:
> Hello All,
>
> I have a problem in that on occasion I need to generate very large arrays
> that won't fit into memory. For what I'm doing, calling linspace is
> convenient, so I'd like to be able to use it. A very simple example of my
> problem is the case:
>
> a = linspace(start, stop, very_big_num)
>
> As a python/scipy newbie, I'm just becoming familiar with appropriate
> coding patterns. One thought was whether it is possible to use generators to
> defer the array creation. I'd like to be able to use linspace (pleasantly
> simple) but defer generation of the complete array, returning individual
> values or a range of values on demand. My question is, whether the following
> generator expression is appropriate or not? Or whether linspace will fill
> its array (and therefore overflow memory)?
>
> g = (val for val in linspace(start, stop, very_big_num))
>
> So will this work?
>
> I realize that it is possible for me to write my own version of linspace
> as a generator--but hoping I don't have to.
>
> If the above generator expression doesn't work, are there any other
> straight forward coding patterns that will do what I'm looking for?
>
>
> Thanks for the help.
>
>
> My best,
> Jo
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Dr Joseph Anderson
> Lecturer in Music
>
> School of Arts and New Media
> University of Hull, Scarborough Campus,
> Scarborough, North Yorkshire, YO11 3AZ, UK
>
> T: +44.(0)1723.357341 T: +44.(0)1723.357370 F: +44.(0)1723.350815
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> *****************************************************************************************
> To view the terms under which this email is distributed, please go to
> http://www.hull.ac.uk/legal/email_disclaimer.html
>
> *****************************************************************************************
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>
--
Lorenzo Bolla
lbolla at gmail.com
http://lorenzobolla.emurse.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080319/cf60a3b7/attachment.html>
More information about the SciPy-User
mailing list