[Gretl-devel] imaxc/imaxr

Sven Schreiber svetosch at gmx.net
Wed Apr 22 11:21:30 EDT 2015


Am 21.04.2015 um 13:25 schrieb Riccardo (Jack) Lucchetti:
>
> Folks, consider this:
>
> <hansl>
> x = imaxr({1,2,1,2,1,2})
> </hansl>
>
> At present, this returns the scalar 2, but I wonder if it shouldn't
> instead return a row vector holding {2,4,6}. But then, generalisation to
> the case when the argument to imaxr is a matrix with more than 1 row
> becomes awkward. Thoughts?
>

A Jack-style answer might be: You could use
<hansl>
matrix m1 = {1,2,1,2,1,2}
matrix check = selifc( seq(1, cols(m1)), (m1 .>= max(m1)) )
print check
</hansl>

to get the vector output, but I know that that's not the point of the 
question and you knew that already.

FWIW, (Python's) Numpy's argmax() and argmin() functions explicitly note 
that:
"In case of multiple occurrences of the maximum values, the indices 
corresponding to the first occurrence are returned."

I'd say that's fine, and for other use cases I'd tend to recommend 
workarounds such as the above. Alternatively, perhaps an optional second 
argument to the iminr/iminc/imaxc/imaxr functions to request a check for 
all occurrences?

(BTW, it seems suboptimal to me to have four different function names 
that essentially do the same thing. But probably too late now.)

cheers,
sven



More information about the Gretl-devel mailing list