copy a numpy array

Francesco Guerrieri f.guerrieri at gmail.com
Wed Jan 9 04:22:55 EST 2008


On Jan 9, 2008 6:35 AM, jimgardener <jimgardener at gmail.com> wrote:
> thanx guys for the replies
> need a little clarification
>
> srcarray=array([1.2,2.3,3.4,4.5,5.6])
> destarray=array(srcarray,copy=False)
>
> then
> srcarray[2]=99.9
> will cause the change to be reflected in both src and dest.
> doesn't that mean data is shared between both arrays?
>
> but if i do
> destarray=array(srcarray)
> or
> destarray=srcarray.copy()
> then the change in one array will not affect the other,meaning no data
> sharing
> ...want to know if  my understanding is right
> jim

You're right, I wrote too quickly and so I gave a wront information! sorry! :-)

Just try the following:
Apart from the copy method (which other have correctly pointed to),
the correct version  is simply:

a = numpy.array([1,2])
b = numpy.array(a)

and now try modifying one of them.

bye
Francesco



More information about the Python-list mailing list