Copies with MaskedArray?
![](https://secure.gravatar.com/avatar/43b43dbafd14539136100e0028ba01cd.jpg?s=120&d=mm&r=g)
Hi, I'm creating a structured numpy array in C, wrapping it with a MaskedArray and passing this to a Python script: ... PyObject *arr = PyArray_NewFromDescr(&PyArray_Type, descr, 1, &longCount, &pointSize, data, NPY_ARRAY_WRITEABLE, nullptr); // Now wrap the created array in a MaskedArray. PyObject *module = PyImport_ImportModule("numpy.ma"); PyObject *dict = PyModule_GetDict(module); PyObject *keys = PyDict_Keys(dict); PyObject *o = PyDict_GetItemString(dict, "MaskedArray"); PyObject *args = PyTuple_New(1); PyTuple_SetItem(args, 0, arr); m_directArray = PyObject_CallObject(o, args); This works fine and the data is seen in python as it was in C. What I'd like to happen is to have changes made to the array in Python be reflected in the memory that was passed in. This seems to work in some cases. Given the dtype: [('X', '<f8'), ('Y', '<f8'), ('Z', '<f8'), ('OffsetTime', '<u4')] I can do something like: X = 10 in Python and appropriate data is set in the C-allocated memory. However, this fails: X *= 10 in that it seems to make a copy of the array IF the mask of the values aren't all set to 0 in the source. Is there something I can do to get operations on the MaskedArray to operate on the data in place as would occur with a raw ndarray? Thanks, -- Andrew Bell andrew.bell.ia@gmail.com
participants (1)
-
Andrew Bell