On Wed, 22 Apr 2015, Sven Schreiber wrote:
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.
:D I've been out-myself-ed!
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."
This makes sense. I'm not sure if in fact we follow this policy, but if we
agree we should I can have a go the the C code to make sure we do, and of
course update the docs.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------