Iterating over multiple arrays

Very often, it is desireable to iterate over several arrays at the same time. The universal functions are an example of this kind of behavior. If all you want to do is iterate over arrays with the same shape, then simply creating several iterator objects is the standard procedure. For example, the following code iterates over two arrays assumed to be the same shape and size (actually objl just has to have at least as many total elements as does obj2):

/* It is already assumed that obj1 and obj2 are ndarrays of the same shape and size.

iterl = (PyArraylterObj ect *)PyArray_IterNew(obj1) ;

iter2 = (PyArraylterObj ect *)PyArray_IterNew(obj2) ;

if (iter2 == NULL) goto fail; /* assume iter1 is DECREF'd at fail *

/* process with iter1->dataptr and iter2->dataptr */ PyArray-ITERJSTEXT (iterl) ; PyArray_ITER_NEXT ( iter2 ) ;

0 0

Post a comment