[Numpy-discussion] In-place operations

Pierre Thibault thibault at physics.cornell.edu
Tue Sep 12 12:17:22 CDT 2006


Hello again,

On 9/12/06, Francesc Altet <faltet at carabos.com> wrote:
> Hello Pierre,
> [...]
>
> Well, in some way, there is a temporary array creation that is
> immediately bound to B, so in the end, the temporary is not so
> temporary, but a new (bounded) object. Obviously, the object that was
> referencing B is freed (unless there is another reference to it).

ok, I guess I was aware of all that. My worries are related to two cases:
1) When the mere creation of a new array is prohibitive.
2) When what I really want to change is the _content_ of an array.
Using assignment (=) disconnects B from the array it refers to, so
that what used to be true (C=B) is not anymore.

I understant that B[:] = ...  solves the problem 2), though I don't
know if this notation is recommended; but I would like to know if
there is anyway to solve 1), in the way ufuncs can do.

I had fun using kde's "performance monitor" (ksysguard) to see the
difference between

a = numpy.random.rand(2048,2048) + 1j * numpy.random.rand(2048,2048)
a = numpy.exp(a)

and

a = numpy.random.rand(2048,2048) + 1j * numpy.random.rand(2048,2048)
numpy.exp(a,out=a)

Not only is the latter faster, but I could see a large glitch in the
memory usage for the former.

Pierre

-- 
Pierre Thibault
616 Clark Hall, Cornell University
(607) 255-5522




More information about the Numpy-discussion mailing list