[Numpy-discussion] immutable numpy arrays

Robert Kern robert.kern at gmail.com
Wed Dec 17 17:24:06 EST 2008


On Wed, Dec 17, 2008 at 15:52, Geoffrey Irving <irving at naml.us> wrote:
> Currently numpy arrays are either writable or unwritable, but
> unwritable arrays can still be changed through other copies.  This
> means that when a numpy array is passed into an interface that
> requires immutability for safety reasons, a copy always has to be
> made.
>
> One way around this would be to add a NPY_IMMUTABLE flag signifying
> that the contents of the array will never change through other copies.

This is not possible to guarantee. With the __array_interface__, I can
make a numpy array point at any addressable memory without its
knowledge. We can even mutate "immutable" str objects, too.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list