Why can't numpy array be restored to saved value?
pjfarley3 at earthlink.net
pjfarley3 at earthlink.net
Thu Nov 26 13:10:48 EST 2020
> -----Original Message-----
> From: Christian Gollwitzer <auriocus at gmx.de>
> Sent: Thursday, November 26, 2020 3:26 AM
> To: python-list at python.org
> Subject: Re: Why can't numpy array be restored to saved value?
>
> Am 25.11.20 um 07:47 schrieb pjfarley3 at earthlink.net:
> > Why isn't the final value of the numpy array npary in the following code the
> > same as the initial value before some but not all elements of the array were
> > changed to a new value?
> >
> > I know I am missing something basic here. I thought I understood the
> > concepts of immutable vs mutable values but obviously I missed something.
> >
<Snipped>
>
> Because this does not copy the array, rather it creates a view into the
> original array. This is an optimization to avoid copying. If you want a
> copy, do svary = npary.copy()
Thank you for the explanation. I did indeed find that using the copy() function did what I needed to do.
Peter
More information about the Python-list
mailing list