Roger posted a link to this question of Dijkstra's:
>  How would you represent a  more complex operation,
>  for example, the sum of all elements of a matrix 
>  which are equal to the sum of the corresponding row 
>  and column indices? 


Oleg pondered:
>  What is the standard J answer?

Whenever I want a matrix of indicies I think first of the idiom  (#:i.)@:$  .  
So, in this case, I would write something along the lines of:

           (+/@:#&,~ ( = (+/@#: i.)@:$)) i. 3 4
        6

           (+/@:#&,~ ] = (+/@#: i.)@:$)  i. 3 4
        6

           (+/@ #&,~ ] = (+/@#: i.)@ $)  i. 3 4
        6
  
with the particular style chosen to suit the objective.  In Dyalog APL (at 
least), monadic iota (the analog to  i.y  )  already produces a matrix of 
(enclosed) indicies, so the analogous verb might be briefer.  I should really 
buy one of those cheap "personal use" licenses, so I could play with ideas like 
this.

-Dan

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

Reply via email to