Numeric: difference between zeros((3,)'f') and array([0.0,0.0,0.0])
Marcus Stojek
stojek at part-gmbh.de
Tue Feb 4 16:16:36 CET 2003
Hi,
I have a written c extension using swig. (see typemap below). The
python function expects a Numeric.array as input.
(Python 2.2 Numeric 22.0 Win NT)
This array is filled with result values in the c extension. ok.
if I create the array with
L=[0.0 for i in range(1000)]
a=Numeric.array(L)
everything works fine and a is filled with results. If I use:
b=Numeric.zeros((1000,),'f')
b still contains 0.0 only. iscontiguous() gives 1 for a and b.
In my interpretation this means that for the first case a is passed by
PyArray_ContiguousFromObject because $input already is
contiguous and for the second case a contiguous copy of $input (b) is
made. (Besides of getting no results i can watch my heap grow if
cfunc is called repeatedly with the same input b)
Can anybody explain how a and b differ?
Thanks
marcus
//typdef double d_list;
%typemap(in) (d_list *, int) {
int size;
if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a sequence as double
(in)");
return NULL;
}
size=PySequence_Length($input);
PyArrayObject *data;
// data = (PyArrayObject *) $input; //don't know why.. doesn't work
data = (PyArrayObject *) PyArray_ContiguousFromObject($input,
PyArray_DOUBLE, 1, 0);
$1= (double *) data->data;
$2= size;
}
More information about the Python-list
mailing list