numpy.ndarray.setflags#
method
- ndarray.setflags(write=None,align=None,uic=None)#
Set array flags WRITEABLE, ALIGNED, WRITEBACKIFCOPY,respectively.
These Boolean-valued flags affect how numpy interprets the memoryarea used bya (see Notes below). The ALIGNED flag can onlybe set to True if the data is actually aligned according to the type.The WRITEBACKIFCOPY flag can never be setto True. The flag WRITEABLE can only be set to True if the array owns itsown memory, or the ultimate owner of the memory exposes a writeable bufferinterface, or is a string. (The exception for string is made so thatunpickling can be done without copying memory.)
- Parameters:
- writebool, optional
Describes whether or nota can be written to.
- alignbool, optional
Describes whether or nota is aligned properly for its type.
- uicbool, optional
Describes whether or nota is a copy of another “base” array.
Notes
Array flags provide information about how the memory area usedfor the array is to be interpreted. There are 7 Boolean flagsin use, only three of which can be changed by the user:WRITEBACKIFCOPY, WRITEABLE, and ALIGNED.
WRITEABLE (W) the data area can be written to;
ALIGNED (A) the data and strides are aligned appropriately for the hardware(as determined by the compiler);
WRITEBACKIFCOPY (X) this array is a copy of some other array (referencedby .base). When the C-API function PyArray_ResolveWritebackIfCopy iscalled, the base array will be updated with the contents of this array.
All flags can be accessed using the single (upper case) letter as wellas the full name.
Examples
>>>importnumpyasnp>>>y=np.array([[3,1,7],...[2,0,0],...[8,5,9]])>>>yarray([[3, 1, 7], [2, 0, 0], [8, 5, 9]])>>>y.flags C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : True WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False>>>y.setflags(write=0,align=0)>>>y.flags C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : True WRITEABLE : False ALIGNED : False WRITEBACKIFCOPY : False>>>y.setflags(uic=1)Traceback (most recent call last): File"<stdin>", line1, in<module>ValueError:cannot set WRITEBACKIFCOPY flag to True