# [Numpy-discussion] Getting the indexes of the myarray.min()

Perry Greenfield perry at stsci.edu
Thu May 13 06:29:02 CDT 2004

```Robert Kern wrote:

> > 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
> value as you go. Discard the list of indices and start again if you get
> a new minimum value.
>
True enough (though I suspect some special cases may not work any
faster, e.g., an array of all zeros with the last element equal to
-1; you spend all the time copying indices for nearly the whole damn
thing for no purpose). There are a bunch of things that can be done
to eliminate multiple passes but they tend to lead to many different
specialized functions. One has to trade off the number of such functions
against the speed savings. Another example is getting max and min values
for an array. I've long thought that this is so often done they could
be done in one pass. There isn't a function that does this yet though.

> >>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?.
> >>
> >
> > 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
> scheme would be very useful not because of the space factor but the time
> saved by being able to use the symmetric algorithms in LAPACK. I think.
>
I'd agree that that would be a much stronger motivating factor.

Perry

```