Dinesh B Vadhia
Fri Mar 7 16:39:18 CST 2008
Thanks! What I need to do is 1) create a very large sparse matrix A (with integer 1's and A is very sparse), 2) pickle the matrix and 3) unpickle it when needed in various modules.
Performance of unpickling (ie. step 3) is important as the matrix is very large. Hence, in step 1, I didn't really want to initialize the matrix A with zeroes() because it is adding unnecessary 'weight' to the pickling/unpickling and hence performance.
Appreciate your thoughts. Cheers!
Date: Thu, 6 Mar 2008 20:05:50 +0100
From: "Anne Archibald" <firstname.lastname@example.org>
Subject: Re: [SciPy-user] empty()
To: "SciPy Users List" <email@example.com>
Content-Type: text/plain; charset=UTF-8
On 06/03/2008, Dinesh B Vadhia <firstname.lastname@example.org> wrote:
> I have to ask but in
> > A= scipy.asmatrix(scipy.empty((I, J), int))
> does the empty() function really 'empty' out the array or does it just
> allocate space for the array leaving spurious content in the array?
> I want to make sure before starting to use empty() with wild abandon!
empty() creates a fresh new array but does not touch the contents.
Thus they can be anything; for freshly-allocated very large arrays
they may be all zeros on some systems, but otherwise they usually
contain malloc bookkeeping information or old data. Thus the array is
packed with spurious content.
It is probably a good idea to either use
A = numpy.zeros(<whatever>)
or, if you want to be sure to notice if you fail to set some element
of the array,
A = numpy.zeros(<whatever>)/0.0
(this latter ensures that the array is filled with "Not a Number", a
special floating-point value that indicates invalid data). Only if you
find your program has no bugs and is too slow is empty() a good idea.
It's usually also worth trying to construct the array directly with
the correct values - for example using arange() or eye() - rather than
filling in values after the fact.
I should also point out that both empy() and asmatrix() are *numpy*
functions, not scipy. That they are also available in scipy is a
historical quirk; scipy simply reexports some of the numpy functions
in its own namespace (complicating the process of finding the real
scipy functions). It's a better idea to access these functions through
the numpy namespace.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-user