Numeric, how to do in place full-array modification?

Ionel Simionescu ionel at psy.uva.nl
Sat Oct 2 17:05:01 EDT 1999


Hi,

I want to do the following:

for t in range( T ):
   net = dot( C, x )
   x   = A*net*(1-net)

Because these arrays might turn to be large, I want to pre-alloate <net> and
write both <net> and <x> in place rather than creating new arrays.


Intuitively, I would write it like:

net = zeros(shape, typecode)
for t in range( T ):
    net[:] = dot( C, x)
    x[:]   = A*net*(1-net)

But, I recall that, when on the right hand side, a[:] is used precisely to
create a new sequence. Therefore, I'm unclear about the semantics of this
form.

So, the question is: how to modify in place a full array?

Thank you,
ionel






More information about the Python-list mailing list