Numeric: difference between zeros((3,)'f') and array([0.0,0.0,0.0])

Marcus Stojek stojek at
Tue Feb 4 14:44:04 CET 2003

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)]

everything works fine and a is filled with results. If I use:


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?


//typdef double d_list;
%typemap(in) (d_list *, int) {
  int size;
  if (!PySequence_Check($input)) {
    PyErr_SetString(PyExc_ValueError,"Expected a sequence as double
    return NULL;
  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