[MATRIX-SIG] PyArrayObjects

Dale Bertrand Dale_Bertrand@brown.edu
Tue, 29 Jul 1997 17:30:24 -0400 (EDT)


I am writing a small python module in c which needs to access the internals of a
 PyObject (which is really a PyArrayObject).  I've been using the function:
 PyArray_ContiguousFromObject to extract the PyArrayObject from the PyObject and
 then modify the data via arrayobject->data.

Unfortunately, it seems to me that PyArray_ContiguousFromObject makes a copy of 
the PyObject which I _must_ return to see my changes.  I would like my c functio
n to simply access and modify the array data without making a copy.


How do I access the array data without copying the Object?

A snip of code:

static PyObject *
do_array(PyObject *self,PyObject *args)
{
    PyObject *op;  /* <- I would like to edit this */
    PyArrayObject *mp; /*  <-without making this  */ 
    int h,w;
    int ubound[1];
    int lbound[1];
    
    TRY(PyArg_ParseTuple(args, "Oii", &op, &lbound , &ubound));
    TRY(mp = (PyArrayObject *)PyArray_ContiguousFromObject(op,PyArray_CHAR, 2, 2
));

    h = mp->dimensions[0];
    w = mp->dimensions[1];
    
    threshold((unsigned char *)mp->data, (int *)lbound , (int*)ubound, 1, w*h);
    Py_DECREF(mp);
    return (PyObject *)mp;  /* I do not want to have to return this */
}


Thanks
-Dale Bertrand


----------------------------------
E-Mail: Dale Bertrand <Dale_Bertrand@brown.edu>
Date: 29-Jul-97
----------------------------------

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________