Gary -
the side-effect of '{.&>' is coincidental - it happens because the right and
left arguments are the same shape. The other expression '{."0' would be
more appropriate if this is what the expression is intended to mean.
I would be more likely to use the former expression in a case like this
width{.&>items
to turn a list of items into a table with width "width" (where the width is
a scalar).
However, this points up that, In your example, for both expressions, the
parts of the left-hand argument smaller than the greatest one are moot.
That is, for any vector "vec", the result of
vec{.&>items
or
vec{."0 items
is the same as the result of
(>./vec){.&>items
or
(>./vec){."0 items
because the implicit "disclose" after the "take" pads each result to the
length of the longest one.
Generally, you would use a multi-dimensional "take" with the length of the
left argument less than or equal to the rank of the noun on the right, e.g.
_3 _4{. i. 5 6
14 15 16 17
20 21 22 23
26 27 28 29
$_3 _4{. i. 5 6 7 NB. Just show shape to avoid large display.
3 4 7
$_2 3 _4{. i. 4 5 6 8 9 NB. Just show shape to avoid large display.
2 3 4 8 9
Scanning my own code, I most usually use "take" with a scalar left argument,
e.g.
FLDTS=: ;100#.&.>3{.&.>1{"1 tree NB. Num yyyymmdd dates
mvSed=. (mvSed i.&.>'*'){.&.>mvSed NB. Keep only part of string
before first '*'
or monadically:
cc=. cc#~'!'~:{.&>0{"1 cc NB. Only lines without initial '!'.
p1=: <@(* $ ]) ,~ ;@((((<: {.&>) # ,&.>) $:)&.> |.)@}...@i. NB. All
partitions of y
p1 4
+-------+-----+---+---+-+
|1 1 1 1|1 1 2|1 3|2 2|4|
+-------+-----+---+---+-+
It really depends on what you mean to do.
Regards,
Devon
On Wed, May 13, 2009 at 9:13 PM, gary ng <[email protected]> wrote:
> On Wed, May 13, 2009 at 6:47 AM, Devon McCormick <[email protected]>
> wrote:
>
> > Hi -
> >
> > you might want to learn more about "rank":
> > http://www.jsoftware.com/jwiki/Essays/Rank .
> >
>
> Thanks Devon, Don and Bill for the explanation about ranks and other
> alternatives. Need some time to read the ranks stuff in more detail.
>
> Are there any hidden 'gem' or reason to say '{.&>' rather than '({."0)' as
> to me the only reason for the &> is to modify the rank of {. ?
>
> It seems to be using the 'side effect'(force rank 0 because of '>'), for
> an
> experienced Jer, it may be very obvious but still a questionable practice ?
> ----------------------------------------------------------------------
> 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