[Numpy-discussion] Do you find this behavior surprising?

Benjamin Root ben.root at ou.edu
Wed Mar 25 16:45:07 EDT 2015


I fail to see the wtf.

flags = a.flags

So, "flags" at this point is just an alias to "a.flags", just like any
other variable in python

"flags.writeable = False" would then be equivalent to "a.flags.writeable =
False". There is nothing numpy-specific here. a.flags is mutable object.
This is how Python works.

Ben Root



On Wed, Mar 25, 2015 at 4:36 PM, Jaime Fernández del Río <
jaime.frio at gmail.com> wrote:

>
> >>> import numpy as np
> >>> a = np.arange(10)
> >>> flags = a.flags
> >>> flags
>   C_CONTIGUOUS : True
>   F_CONTIGUOUS : True
>   OWNDATA : True
>   WRITEABLE : True
>   ALIGNED : True
>   UPDATEIFCOPY : False
> >>> flags.writeable = False
> >>> a.flags
>   C_CONTIGUOUS : True
>   F_CONTIGUOUS : True
>   OWNDATA : True
>   WRITEABLE : False  <--- WTF!!??
>   ALIGNED : True
>   UPDATEIFCOPY : False
>
> I understand why this is happening, and that there is no other obvious way
> to make
>
> a.flags.writeable = False
>
> work than to have the return of a.flags linked to a under the hood.
>
> But I don't think this is documented anywhere, and wonder if perhaps it
> should.
>
> Jaime
>
> --
> (\__/)
> ( O.o)
> ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
> de dominación mundial.
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150325/2b718b63/attachment.html>


More information about the NumPy-Discussion mailing list