On my machine the timings are 

           '5.2d' 8!:2 (%"1 <./) 100 ts&> ic ,L:0 ' D'
 1.66 1.01
 1.00 1.00
 1.21 1.33

which makes more sense to me.

Henry Rich

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Dan Bron
> Sent: Tuesday, October 28, 2008 6:50 PM
> To: Programming forum
> Subject: Re: [Jprogramming] Index of first one in columns
> 
> John wrote:
> >  icol=:(] i. 1:)"1@:|:
> >  Is there a better way (that avoids the transpose)?
> 
> Apropos of a recent thread, you can use cut:
> 
>          D   =:  [EMAIL PROTECTED]&2 ] 400 400       NB.  Test data
>          
>          ic0 =:  (] i. 1:)"1@:|:        NB.  Original
>          ic1 =:  i.&1"1@|:              NB.  Variation
>          ic2 =:  ('';1) i.&(,1);.1 ]    NB.  Avoid |:
>          
>          ic  =:  ic0`ic1`ic2             
>          
>          (-: 1&|.) ic`:0 D              NB.  Identical results
>       1
>          
>          ts  =:  6!:2 , 7!:2@:]
>          '5.2d' 8!:2 (%"1 <./) 100 ts&> ic ,L:0 ' D'
>        2.33 1.01
>        1.28 1.00
>        1.00 1.33
>          
> So cut not only avoids transpose, but is faster (this 
> actually surprises me).
> 
> In any case, I suspect you wanted to avoid  |:  not for 
> performance reasons, but because it feels too "forced".  At 
> least, I've often wanted a "natural" way to access different 
> axes of arrays (similar to the way that  f/ table  appears to 
> act on the columns of the table).  If that's your question:  
> I believe transpose and cut are the best we've got.
> 
> Gosi wrote:
> >  {. I.
> 
> This won't work.  You still need the transpose (i.e. you need 
>  [EMAIL PROTECTED]@|:  to get the desired result).  Also, since  [EMAIL 
> PROTECTED]  
> isn't optimized (yet), you're doing extra work for no benefit.
> 
> -Dan
> ----------------------------------------------------------------------
> 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