On 6/12/07, Will Slade <[EMAIL PROTECTED]> wrote:
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.
As you posted this to the J programming forum, I'm presuming you're
interested in knowing how to do this from a J point of view as well.
Of course, J makes this rather simple (since you can ignore trailing
dimensions when you use its index function). But some approaches
from J should also be valid in APL.
For example, let's say your array has dimensions of either 2 3 5 7
or 2 3 4, and you want the second item, and you want to limit yourself
to J operations which correspond to APL operations. (I'll presume your
APL has nested arrays).
index=:4 :0
shape=.$y
inds=:i.&.>shape
inds=. (<x),}.inds
indices=. >+/&.>/inds*&.>|.*/\|.}.shape,1
indices { ,y
)
Translation notes:
$ is rho, =. is gets and }. is 1 drop
i.&.> is iota each
(<x),}.inds can instead use indexing or whatever you like
>+/&.>/ is jot dot plus reduce, then removing the nesting
indices {,y is (,y)[indices]
Anyways, I think this approach should work for most APLs,
but I haven't actually tried it.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm