From: Robert K. <rk...@uc...> - 2004-05-13 00:27:44
|
Perry Greenfield wrote: > =C1lvaro Tejero Cantero wrote: >=20 >>It works great... but what about efficiency? If I do times.min() and >>then numarray.nd_image.minimum_positioan(times) I am running twice >>essentially the same extremum-finding routine, which is prohibitibe for >>large N..., am I right? >> >=20 > Well, yes. But when you ask to find all the things that equal > the minimum, you pretty much must look twice (if you want to know > where they all are if more than one). Once to determine the > minimum, the next time to locate all of them. Nah, you can accumulate indices corresponding to the current minimum=20 value as you go. Discard the list of indices and start again if you get=20 a new minimum value. minval =3D data[0] # let's suppose data is a vector for demonstration minindices =3D [0] for i in xrange(1, len(data)): x =3D data[i] if x < minval: minindices =3D [i] minval =3D x elif x =3D=3D minval: minindices.append(i) Whether or not this is faster (when implemented in C) than going over it=20 twice using numarray functions is another question. My guess: not enough. [snip] >>Yes... although for the problem at hand that motivated my query, my >>times matrix is symmetric... I don't really need all the minima, but >>does numarray have any special datatype for symmetric matrixes, that >>prevents storage of unneded (e.g. supradiagonal) elements?. >> >=20 > Not for special cases like this. One could probably write a special > subclass to do this, but for a savings of a factor of 2 in memory, > it usually would not be worth the trouble (unlike sparse matrices) OTOH, having subclasses that follow LAPACK's symmetric packed storage=20 scheme would be very useful not because of the space factor but the time=20 saved by being able to use the symmetric algorithms in LAPACK. I think. > Perry --=20 Robert Kern rk...@uc... "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter |