numpy.ndarray.flags#
attribute
- ndarray.flags#
Information about the memory layout of the array.
Notes
The
flags
object can be accessed dictionary-like (as ina.flags['WRITEABLE']
),or by using lowercased attribute names (as ina.flags.writeable
). Short flagnames are only supported in dictionary access.Only the WRITEBACKIFCOPY, WRITEABLE, and ALIGNED flags can bechanged by the user, via direct assignment to the attribute or dictionaryentry, or by calling
ndarray.setflags
.The array flags cannot be set arbitrarily:
WRITEBACKIFCOPY can only be set
False
.ALIGNED can only be set
True
if the data is truly aligned.WRITEABLE can only be set
True
if the array owns its own memoryor the ultimate owner of the memory exposes a writeable bufferinterface or is a string.
Arrays can be both C-style and Fortran-style contiguous simultaneously.This is clear for 1-dimensional arrays, but can also be true for higherdimensional arrays.
Even for contiguous arrays a stride for a given dimension
arr.strides[dim]
may bearbitrary ifarr.shape[dim]==1
or the array has no elements.It doesnot generally hold thatself.strides[-1]==self.itemsize
for C-style contiguous arrays orself.strides[0]==self.itemsize
forFortran-style contiguous arrays is true.- Attributes:
- C_CONTIGUOUS (C)
The data is in a single, C-style contiguous segment.
- F_CONTIGUOUS (F)
The data is in a single, Fortran-style contiguous segment.
- OWNDATA (O)
The array owns the memory it uses or borrows it from another object.
- WRITEABLE (W)
The data area can be written to. Setting this to False locksthe data, making it read-only. A view (slice, etc.) inherits WRITEABLEfrom its base array at creation time, but a view of a writeablearray may be subsequently locked while the base array remains writeable.(The opposite is not true, in that a view of a locked array may notbe made writeable. However, currently, locking a base object does notlock any views that already reference it, so under that circumstance itis possible to alter the contents of a locked array via a previouslycreated writeable view onto it.) Attempting to change a non-writeablearray raises a RuntimeError exception.
- ALIGNED (A)
The data and all elements are aligned appropriately for the hardware.
- WRITEBACKIFCOPY (X)
This array is a copy of some other array. The C-API functionPyArray_ResolveWritebackIfCopy must be called before deallocatingto the base array will be updated with the contents of this array.
- FNC
F_CONTIGUOUS and not C_CONTIGUOUS.
- FORC
F_CONTIGUOUS or C_CONTIGUOUS (one-segment test).
- BEHAVED (B)
ALIGNED and WRITEABLE.
- CARRAY (CA)
BEHAVED and C_CONTIGUOUS.
- FARRAY (FA)
BEHAVED and F_CONTIGUOUS and not C_CONTIGUOUS.