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

Reply via email to