[Numpy-discussion] immutable arrays

Travis Oliphant oliphant.travis at ieee.org
Wed Sep 20 13:18:19 CDT 2006


Martin Wiechert wrote:
> Hi list,
>
> I just stumbled accross NPY_WRITEABLE flag.
> Now I'd like to know if there are ways either from Python or C to make an 
> array temporarily immutable.
>   
Just setting the flag

Python:

  make immutable:
  a.flags.writeable = False

  make mutable again:
  a.flags.writeable = True


C:

  make immutable:
  a->flags &= ~NPY_WRITEABLE

  make mutable again:
  a->flags |= NPY_WRITEABLE


In C you can play with immutability all you want.  In Python you can 
only make something writeable if you either 1) own the data or 2) the 
object that owns the data is itself "writeable"


-Travis





More information about the Numpy-discussion mailing list