The following array creation functions share similar behavior. All but one create a new numarray using the data specified by data. If data is NULL, the routine allocates a buffer internally based on the array shape and type; internally allocated buffers have undefined contents. The data type of the created array is specified by type.
There are several functions to create numarrays at the C level:
void *data, NumarrayType type, int ndim, ...) |
ndim specifies the rank of the array (number of dimensions), and the length of each dimension must be given as the remaining (variable length) list of int parameters. The following example allocates a 100x100 uninitialized array of Int32.
if (!(array = NA_NewArray(NULL, tInt32, 2, 100, 100))) return NULL;
void *data, NumarrayType type, int ndim, maybelong *shape) |
For NA_vNewArray the length of each dimension must be given in an array of maybelong pointed to by shape. The following code allocates a 2x2 array initialized to a copy of the specified data.
Int32 data[4] = { 1, 2, 3, 4 }; maybelong shape[2] = { 2, 2 }; if (!(array = NA_vNewArray(data, tInt32, 2, shape))) return NULL;
int ndim, maybelong *shape, NumarrayType type, void *data, maybelong byteoffset, maybelong bytestride, int byteorder, int aligned, int writable) |
NA_NewAll is similar to NA_vNewArray except it provides for the specification of additional parameters. byteoffset specifies the byte offset from the base of the data array at which the real data begins. bytestride specifies the miminum stride to use, the seperation in bytes between adjacent elements in the array. byteorder takes one of the values NUM_BIG_ENDIAN or NUM_LITTLE_ENDIAN. writable defines whether the buffer object associated with the resulting array is readonly or writable.
int ndim, maybelong *shape, maybelong *strides, NumarrayType type, void *data, maybelong byteoffset, maybelong byteorder, int aligned, int writable) |
NA_NewAllStrides is a variant of NA_vNewAll which also permits the specification of the array strides. The strides are not checked for correctness.
int ndim, maybelong *shape, NumarrayType type, PyObject *buffer, maybelong byteoffset, maybelong bytestride, int byteorder, int aligned, int writable) |
NA_NewAllFromBuffer is similar to NA_NewAll except it accepts a buffer object rather than a pointer to C data. The buffer object must support the buffer protocol. If buffer is non-NULL, the returned array object stores a reference to buffer and locates its data there. If buffer is specified as NULL, a buffer object and associated data space are allocated internally and the returned array object refers to that. It is possible to create a Python buffer object from an array of C data and then construct a numarray using this function which refers to the C data without making a copy.
PyArrayObject*a,PyArrayObject*b) |
PyArrayObject*a,PyArrayObject*b) |
) |
Float32 *f, Int32 *mask) |
Float64*,Int32*) |
PyArrayObject *) |
int) |
int) |
PyObject*) |
int,maybelong*) |
int,maybelong*,PyObject*) |
PyObject*) |
PyArrayObject*,PyObject*) |
PyObject*) |
PyArrayObject *a, long offset) |
PyArrayObject *a, long offset, PyObject*value) |
PyObject*o) |
PyObject*) |
PyObject*) |
PyArrayObject*) |
PyArrayObject*) |
PyArrayObject*to, const PyArrayObject *from) |
Send comments to the NumArray community.