I did previously optimized this. From the J6.03 release notes:
{/: and {/:~ Improved initial writing: 2008-03-20
last updated: 2008-04-09
The dyads x{/:y and x{/:~y can be used to compute order
statistics such as the median. They have been made more
efficient for integer atom x and integer or floating-point
list y . The following benchmarks demonstrate the
improvements.
x=: ?1e6
i=: 1e6 [EMAIL PROTECTED] 2e9
d=: 0.01 * i
ts=: 6!:2 , 7!:[EMAIL PROTECTED] NB. time and space
100 ts 'Expression'
Expression J 6.03 J 6.02 Ratio
x ({/: ) i 0.028988 2.09856e6 0.214498 8.91366e6 7.40 4.25
x ({/:~) i 0.027497 4.19584e6 0.137272 8.91386e6 4.99 2.12
x ({/: ) d 0.045599 4.19571e6 0.340021 8.91366e6 7.46 2.12
x ({/:~) d 0.046481 4.19584e6 0.161224 1.73025e7 3.47 4.12
----- Original Message -----
From: Don Guinn <[EMAIL PROTECTED]>
Date: Friday, October 17, 2008 7:59
Subject: Re: [Jprogramming] index of maximum value
To: Programming forum <[email protected]>
> After I posted this Roger sent a note that he would optimize
> this. And some
> variations of this too. Will be interesting to see what he comes
> up with.
>
> On Thu, Oct 16, 2008 at 7:13 PM, Randy MacDonald
> <[EMAIL PROTECTED]> wrote:
>
> > Hello Don;
> >
> > Neat solution, which probably scans the array (log N) times,
> being a sort
> > and all.
> >
> > Don Guinn wrote:
> >
> >> How about
> >> {.\: ?. 30$100
> >> 9
> >>
> >>
> >> On Sun, Oct 12, 2008 at 9:00 AM, June Kim
> <[EMAIL PROTECTED]> wrote:
> >>
> >>
> >>
> >>> I can get the index of the maximum value easily, first
> getting the
> >>> maximum and then getting the index:
> >>>
> >>> I.@(=>./) ?. 30$100
> >>> 9
> >>>
> >>> Suppose, there is one presence of maximum value in the data.
> >>>
> >>> 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).
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm