gg2a=: 4 : 0
 b=. |:x I.&> }:y
 (b +//. {:y) (<"1 ~.b)} (>:#&>x)$0
)

   x=: /:~&.> 5 7 13 [EMAIL PROTECTED]&.> 1000
   y=: 4 1000 [EMAIL PROTECTED] 1000

   x (gg2a -: Gg2) y
1

See http://www.jsoftware.com/jwiki/Essays/Key
for some uses of "key".



----- Original Message -----
From: "J. Patrick Harrington" <[EMAIL PROTECTED]>
Date: Monday, September 22, 2008 19:44
Subject: Re: [Jgeneral] A Sorting Problem
To: General forum <[email protected]>

> 
> Thanks, Raul! I've replaced the old Gg with Gg2:
> 
> Gg2=: 4 : 0
> 'f1 f2 f3'=. x
> 'a1 a2 a3 a'=. y
> b=. (f1 I. a1),.(f2 I. a2),.(f3 I. a3)
> sums=. b +//. a
> idx=. <"1 ~. b
> 'n1 n2 n3'=. >: >#&.> f1;f2;f3
> sums idx} S=. (n1,n2,n3)$0
> )
> 
> and now the sort adds negligible time to the program.
> I need to learn about "key".
>                                      Patrick
> 
> On Mon, 22 Sep 2008, Raul Miller wrote:
> > On Mon, Sep 22, 2008 at 3:14 PM, J. Patrick Harrington
> > <[EMAIL PROTECTED]> wrote:
> >>  So the problem looks like this: a -- intensity array, 
> size = np (nphotons >
> >> 1e5)
> >> a0, a1, a2 -- tags for position & angle, all size np
> >> f0, f1, f2 -- boundaries of the cells into which I want
> >>              to sort the the photons.
> >> Thus, b0=. f0 I. a0  will be the index which shows into 
> which f0 interval
> >> each photon in "a" falls. The number
> >> of boundaries might be ~40, so there will be 40^3=64000
> >> cells to which the exiting photons might be assigned.
> >
> > I would be inclined to use J's key adverb to perform your sums.
> > If I understand your description correctly, I think I would use:
> >   sums=: (|:b) +//. a
> >   bins=: ~.&.|: b
> >
> > I would also think about replacing b with its transpose since
> > using it as a key suggests that would be more natural.  Perhaps
> > using an expression like:
> >    b=. (f0 I. a0),.(f1 I. a1),.(f2 I. a2)
> >
> > -- 
> > Raul
> > ---------------------------------------------------------------
> -------
> > For information about J forums see 
> http://www.jsoftware.com/forums.htm>
> -----------------------------------------------------------------
> -----
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to