On Thursday 19 May 2005 12:48, Uri Guttman wrote: > >>>>> "LP" == Luke Palmer <[EMAIL PROTECTED]> writes: > > LP> On 5/18/05, Anthony Heading <[EMAIL PROTECTED]> wrote: > >> Is there a way to target hyperoperators at different axes > >> of a multi-dimensional array? This is an attractive > >> feature of various APL-like languages, viz. e.g. in J: > >> > >> a =. 2 5 $ i. 7 - a simple 2-by-5 array > >> a > >> 0 1 2 3 4 - like this > >> 5 6 0 1 2 > >> > >> > >> +/"1 a - sum reduce over axis 1 > >> 10 14

## Advertising

That is, break the array into rows, and reduce each row. > LP> [+]<< @a > > >> +/"2 a - sum reduce over axis 2 > >> 5 7 2 4 6 Actually, that's sum reduce over planes, which gives the default behavior when applied to a single plane, of breaking the plane into rows, and adding the rows to each other. The result is the same as from +/a . The rank conjunction (") is tersely explained at http://www.jsoftware.com/books/help/dictionary/intro20.htm and more fully in The J Primer, J for C Programmers, and other online publications at http://www.jsoftware.com/publications_books.htm > LP> Can't think of any for this one. Or maybe it's this one > that I can LP> think of it for, and the other one which I > can't. > > i can't spit out the syntax but here is the conceptual way i > would do it. we do have multidimensional slices so we could > grab each slice (maybe with zip?) and pass that to [+] and > then grab the list of results back into a array/matrix with > one less dimension than the original. Exactly how Iverson conceived rank for reduction. > so it would be something like this: (very wacko pseudo code): > > @in[ * ; 2 ; * ] ==> > map [+] ==> > @out > > that was an (bad) attempt to slice the third entry in the > second dimension to be summed. You might find it useful to examine this published source code for an early version of J http://www.math.uwaterloo.ca/apl_archives/j/early_j/src/j7/ to see how Iverson's crew implemented rank. The numbering is confusing, because they restarted at some point, so J5.0.4 is current. > LP> I think we're beginning to re-invent PDL. APL and J, too. > Poorly. Amen. > but is there a p6 pdl yet? they may not need much with > multi-dim ops, slices, hyper and reduce all built in! also > with type int (patform ints), they can get the dense storage > needed (but losing any dimensional flexibility). > > uri -- Edward Cherlin Generalist & activist--Linux, languages, literacy and more "A knot! Oh, do let me help to undo it!" --Alice in Wonderland http://cherlin.blogspot.com