June Kim asked:
> However, the solution isn't satisfactory to me. Is there a 
> simple single step way of finding the index of the max? That 
> is, the way where you don't need to scan the data twice(once 
> for max, another for index).

Yes, use  (i.>./)  .  It is supported by special code [1]:

           6!:2 '(i.>./)y'                  NB.  Optimized way
        0.00146858

           6!:2'y (i.>./)y'                 NB.  Functionally identical, but 
unoptimized.
        0.00689049

           6!:2'(i.&]>./)y'                 NB.  Ditto
        0.00731627

           6!:2'(4 : ''x i. y'' >./)y'      NB.  Ditto
        0.00697293

           
Relative performance in time and space:

           (>A) ,.  '5.2' 8!:2 (%"1 <./) 100 (6!:2 , 7!:2@:])&> 
A=:'(i.>./)y';'y (i.>./)y';'(i.&]>./)y';'(4 : ''x i. y'' >./)y'
        (i.>./)y            1.00 1.00
        y (i.>./)y          5.04 1.11
        (i.&]>./)y          5.05 1.22
        (4 : 'x i. y' >./)y 5.11 3.94
           
-Dan

[1]   http://www.jsoftware.com/help/release/idotmaxmin.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to