Hi -
you might want to learn more about "rank":
http://www.jsoftware.com/jwiki/Essays/Rank .
The "take" verb has rank "_ 1 _" (as seen at the top of its entry when you
click on "{." from the Vocabulary page); the latter two numbers "1 _" are
the default left and right argument ranks. This means that the verb applies
vectors (rank 1) on the left to entire arrays (rank _) on its right. So,
$3 2 1{.3
3 2 1
but modifying the verb with "&>" causes each element on the left to be
applied to each element on the right:
$3 2 1{.&>3
3 3
3 2 1{.&>3
3 0 0
3 0 0
3 0 0
In the example you gave, it might be clearer if you compared the results of
"&.>" (notice the "dot" in the middle) to "&>":
3 2 1{.&.>3 2 1
+-----+---+-+
|3 0 0|2 0|1|
+-----+---+-+
Disclosing the result of this
>3 2 1{.&.>3 2 1
3 0 0
2 0 0
1 0 0
gives the same result as your original expression:
3 2 1{.&>3 2 1
3 0 0
2 0 0
1 0 0
Hope this helps,
Devon
On Tue, May 12, 2009 at 9:17 PM, gary ng <[email protected]> wrote:
> Hi,
> I am learning J and came across the above verb but failed to reason how it
> works.
>
> 3 2 1 {.&> 3 2 1
> 3 0 0
> 2 0 0
> 1 0 0
>
> _3 _2 _1 {.&> 3 2 1
> 0 0 3
> 0 2 0
> 1 0 0
>
> I understand the 'fill'(of those 0) but don't know why it can work on a
> list
> when the left operand is a list rather than an atom.
>
> would appreciate if someone can give me some insight.
> ----------------------------------------------------------------------
> 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