Memory Layout attributes

flags

Array flags provide information about how the memory area used for the array is to be interpreted. There are 6 Boolean flags in use which govern whether or not:

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 if it borrows it from another object (if this is False, the base attribute retrieves a reference to the object this array obtained its data from); 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); UPDATEIFCOPY (U) this array is a copy of some other array (referenced by . base). When this array is deallocated, the base array will be updated with the contents of this array.

Only the UPDATEIFCOPY, WRITEABLE, and ALIGNED flags can be changed by the user. This can be done using the special array-connected, dictionary-like object that the flags attribute returns. By setting elements in this dictionary, the underlying array obect's flags are altered. Flags can also be changed using the method setflags(...). All flags in the dictionary can be accessed using their first (upper case) letter as well as the full name.

Table 3.1: Attributes of the ndarray.

Attribute

Settable

Description

flags

No

special array-connected dictionary-like object with attributes showing the state of flags in this array; only the flags WRITEABLE, ALIGNED, and UPDATEIFGOPY can be modified by setting attributes of this object

shape

Yes

tuple showing the array shape; setting this attribute re-shapes the array

strides

Yes

tuple showing how many bytes must be jumped in the data segment to get from one entry to the next

ndim

No

number of dimensions in array

data

Yes

buffer object loosely wrapping the array data (only works for single-segment arrays)

size

No

total number of elements

itemsize

No

size (in bytes) of each element

nbytes

No

total number of bytes used

base

No

object this array is using for its data buffer, or None if it owns its own memory

dtype

Yes

data-type object for this array

real

Yes

real part of the array; setting copies data to real part of current array

imag

Yes

imaginary part, or read-only zero array if type is not complex; setting works only if type is complex

flat

Yes

one-dimensional, indexable iterator object that acts somewhat like a 1-d array

ctypes

No

object to simplify the interaction of this array with the ctypes module

„array .interface__

No

dictionary with keys (data, typestr, descr, shape, strides) for compliance with Python side of array protocol

__array_struct__

No

array interface on G-level

__array .priority__

No

always 0.0 for base type ndarray

Certain logical combinations of flags can also be read using named keys to the special flags dictionary. These combinations are

FNC Returns F.CONTIGUOUS and not C.CONTIGUOUS

FORC Returns F_CONTIGUOUS or C_CONTIGUOUS (one-segment test).

BEHAVED (B) Returns ALIGNED and WRITEABLE

CARRAY (CA) Returns BEHAVED and C.CONTIGUOUS

FARRAY_(FA) Returns BEHAVED and F.CONTIGUOUS and not C.CONTIGUOUS

0 0

Post a comment