[Jprogramming] APL Question

Mike Day mike_liz.day at tiscali.co.uk
Wed Jun 13 02:53:09 HKT 2007


Not J-programming but...

Here's a simple "non-nested array" method, easily
worked up into an APL function, which might do what
you want. I think it generalises to a rank higher
(or lower) than 3, but you'd best check.  I suggest
you look at the APL*PLUS III definition of transpose, 
which should allow you to do more along the same
lines. 

(NB. I'm adding extra line-feeds to beat T/bird's
line-wrapping)

Using Jim Weigang's transliteration of APL primitives.

Adding J expressions as this is the J prog group! 
J's transpose is a bit different from APL's....
     
      NB. using APL index origin 1
     
      A <- 2 3 4 {rho} {iota} ! 4

      NB. J: A =. i. 2 3 4

      r <- (1-n) {rot} {iota} {rho} {rho} A

      NB. J: r =. n |. i. $ $ A NB. J origin 0

      rtA <- r {transpose} A 

      NB. J: rtA =. r |: A

      tAn <- (1{drop}{rho rtA) {rho} , rtA
     
      NB. J: tAn =. (, $~ (}.@$)) rtA

NB. tAn is the required sub-array, but might need transposing...

      An <- ({gradeup} (-1) {drop} r) {transpose} tAn

      NB. J: An =. (/: }. r) |: tAn

Mike


Will Slade wrote:
> Hello,
>
> I'm crossposting this in the Usenet APL group.
>
> I'm learning APL*PLUS III for work, and I have a question for you
> experienced APLers.
>
> Lets say I have a matrix, A, with dimensions 2 3 4.
>
> A„2 3 4 ½ ¼!4
>
> I can return the first dimension of A like so: A[1;;]
>
> Is there a way to return the nth dimension of A without knowing what the
> dimensions of A are? I'd like the flexibility to arbitrarily return 
> the nth
> dimension, but I don't know how to do this in APL, and the error messages
> are a little cryptic for someone with my inexperience.
>
> Thanks,
> Will
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>


More information about the Programming mailing list