Less simple still but made to look neater by using some names:

   ]mm=. 3 4$10|i.12
0 1 2 3
4 5 6 7
8 9 0 1
   <\./.mm
+-----+---+-+
|0 | | |
+-----+---+-+
|1 4 |4 | |
+-----+---+-+
|2 5 8|5 8|8|
+-----+---+-+
|3 6 9|6 9|9|
+-----+---+-+
|7 0 |0 | |
+-----+---+-+
|1 | | |
+-----+---+-+
   alignrows=: 13 : 'y|.~"(1 0)(-#y){.-i.1{$y'
   aligncols=: (13 : '(i.#y)|."(0 1) y')&.|:
   cumsumdiag=: 13 : '|:(1{$y){.aligncols alignrows +/\./.y'
   cumsumdiag mm
0   5 15 18
4 13 15   7
8   9   0   1

There might be some symmetry between "alignrows" and "aligncols" which would
allow them to be collapsed into one verb,
but it escapes me.


On 11/25/07, R.E. Boss <[EMAIL PROTECTED]> wrote:
>
> Simpler, but not very much.
>
>    ($$ [:(/:@{.{ {:) ;@(</[EMAIL PROTECTED]@$),: [:; <@(+/\.)/.)x
> 0  5 15 18
> 4 13 15  7
> 8  9  0  1
>
>
> R.E. Boss
>
>
> > -----Oorspronkelijk bericht-----
> > Van: [EMAIL PROTECTED] [mailto:programming-
> > [EMAIL PROTECTED] Namens R.E. Boss
> > Verzonden: zondag 25 november 2007 17:26
> > Aan: 'Programming forum'
> > Onderwerp: RE: [Jprogramming] Oblique function
> >
> > The following solution is far from simple.
> >
> >    ($$ (+/"1)@(#: [:i. */)@$ ({:/: /:@{.)@([,&; ([:< +/\.)/.) ,) x
> > 0  5 15 18
> > 4 13 15  7
> > 8  9  0  1
> >
> >
> > R.E. Boss
> >
> >
> > > -----Oorspronkelijk bericht-----
> > > Van: [EMAIL PROTECTED] [mailto:programming-
> > > [EMAIL PROTECTED] Namens Robert O'Boyle
> > > Verzonden: zondag 25 november 2007 16:13
> > > Aan: [email protected]
> > > Onderwerp: [Jprogramming] Oblique function
> > >
> > > I have an arbitrary matrix, x
> > >
> > >
> > >
> > > 0 1 2 3
> > >
> > > 4 5 6 7
> > >
> > > 8 9 0 1
> > >
> > >
> > >
> > > and wish to apply verbs along the diagonals. The oblique verb, /. ,
> > allows
> > > me to do this and with the suffix. \., I can keep the intermediate
> > results
> > >
> > >
> > >
> > > So,
> > >
> > >
> > >
> > > +/\./. x produces matrix
> > >
> > >
> > >
> > > 0 0 0
> > >
> > > 5 4 0
> > >
> > > 15 13 8
> > >
> > > 18 15 9
> > >
> > > 7 0 0
> > >
> > > 1 0 0
> > >
> > >
> > >
> > > which is almost what I want but what I would really like are the
> > > cumulative
> > > results along the diagonals but in the shape of the original matrix.
> > Thus
> > > summing the original matrix x above would produce
> > >
> > >
> > >
> > > 0  5 15 18
> > >
> > > 4 13 15 7
> > >
> > > 8  9 0 1
> > >
> > >
> > >
> > > I looked in the forum archive and couldn't find anything on this.
> > >
> > >
> > >
> > > Is there a simple way of producing my desired matrix from the
> original?
> > >
> > >
> > >
> > > Bob
> > >
> > > ----------------------------------------------------------------------
> > > 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
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to