[Numpy-discussion] immutable numpy arrays
Wed Dec 17 16:51:52 CST 2008
On Wed, Dec 17, 2008 at 2:24 PM, Robert Kern <email@example.com> wrote:
> On Wed, Dec 17, 2008 at 15:52, Geoffrey Irving <firstname.lastname@example.org> 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
>> 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.
In python __array_interface__ just returns a big integer representing
a pointer which can't be used for anything. Well-behaved C code has
to be trusted to care when __array_interface__ marks its data as
unwriteable, so that shouldn't be a problem either.
Is there some other way that arbitrary python code could bypass the
More information about the Numpy-discussion