There are two ways : apply a verb to all ranks or apply a verb to each rank.
allranks=: 1 : '#@:$ 0&(|:u) ]' NB. identical to yours and Millers }: allranks i.3 4 5 0 1 2 3 5 6 7 8 10 11 12 13 20 21 22 23 25 26 27 28 30 31 32 33 Notice that |. allranks -: ];.0 eachrank=: 1 : 0 z=:0$0 for_j. i.>:#$y do. z=:z;~ u"j y end. }.|.z ) < eachrank i.2 3 +-------+-------------+-------+ |+-+-+-+|+-----+-----+|+-----+| ||0|1|2|||0 1 2|3 4 5|||0 1 2|| |+-+-+-+|+-----+-----+||3 4 5|| ||3|4|5|| |+-----+| |+-+-+-+| | | +-------+-------------+-------+ R.E. Boss > -----Oorspronkelijk bericht----- > Van: [EMAIL PROTECTED] [mailto:programming- > [EMAIL PROTECTED] Namens Alistair Tucker > Verzonden: donderdag 4 oktober 2007 15:54 > Aan: [email protected] > Onderwerp: [Jprogramming] shave=: #@:$ 0&(|:}:) ] > > Hiya, > Thanks for your response Raul, > the verb was intended as a monad to be applied to arrays of arbitrary > rank. It removes the topmost item of each dimension. > Originally shave=: #@:$ 0&(0&|:@:}:@:]) ] > The purpose of the outermost 0& was to produce a phrase that would repeat > (0&|:@:}:@:]) a number #@:$ of times. > You are right to say that the outermost 0& is redundant, since I can > produce the same effect with > shave=: #@:$ 0&(|:}:) ] > However the essentials of the implementation remain the same - I rotate > the array through each and every axis and apply curtail }: at each step. > Really I meant to ask whether there might not be a better way to carry > out this operation - i.e. to apply curtail }: through every dimension of > an argument. Rotating the array through its axes in this way must be an > expensive process (isn't it?). > Cheers > Alistair > > > Raul Miller rauldmiller at gmail.com > Thu Oct 4 20:35:35 HKT 2007 > On 10/4/07, Alistair Tucker <alistairtucker at yahoo.co.uk> wrote: > > Seems clumsy and probably inefficient ... was wondering if anybody > > could think of a better way? > > A better way for what? Is your > shave=: #@:$ 0&(0&|:@:}:@:]) > meant to be used as a monad? a dyad? Is it used for all ranks > of arrays? Or only certain ranks (if a dyad, for either left or > right arguments)? > > That said, note that the outer most 0& can be removed, as that > 0 is being provided as a left argument to ] -- and with this removal > the parenthesis become redundant. > > alt1=: #@:$ 0&|:@:}:@:] > > Also, since this is a hook, once this has been rephrased you > no no longer nened the @:] and because }: as a monad has > infinite rank you can further rephrase this as > > alt2=: #@:$ 0&|:@}: > > Ultimately, your result is always going to be a relatively small > non-negative integer (produced by monadic #) so it seems likely > that an alternative expression could be formed for reasonably > constrained domains. However, if you must support both monad > and dyad forms for arguments of arbitrary rank, I'd probably > stick with alt2. > > .. but I'd be tremendously curious as to the purpose of this > expression if the monad and the dyad were both important > for arbitrarily ranked arrays. > > -- > Raul > > > ___________________________________________________________ > Yahoo! Answers - Got a question? Someone out there knows the answer. Try > it > now. > http://uk.answers.yahoo.com/ > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
