What you're reporting with "4:" looks like a bug.

Here's a couple of ways you might deal with multi-dimensional indexes:

   ('.'&=;])aa=. '.es'{~5 5?@$3
+---------+-----+
|0 0 1 1 1|se...|
|0 0 0 1 0|sse.e|
|1 1 0 0 0|..ees|
|0 0 0 0 0|seees|
|0 0 0 0 1|sees.|
+---------+-----+
   ('.'=aa)}aa,:'X'   NB. Replace '.' by 'X'
seXXX
sseXe
XXees
seees
seesX
   ]ixs=. ('.'=,aa)#i.$,aa
2 3 4 8 10 11 24
   $ixs=. ($aa)#:('.'=,aa)#i.$,aa
7 2
   ixs
0 2
0 3
0 4
1 3
2 0
2 1
4 4
   ('0123456') (<"1 ixs)} aa
se012
sse3e
45ees
seees
sees6



On Fri, Jul 15, 2011 at 9:14 AM, Simon Clarkstone <
[email protected]> wrote:

> (Re-sending after adjusting expected from-address.)
>
> I am being confused by the amend adverb's behaviour when applied to a verb.
> http://www.jsoftware.com/help/dictionary/d530v.htm
> I thought that the output of the verb just supplied some indices, and
> } then behaved as if applied to that noun, but that seems not to be
> the case (in j701):
>
>   a =: 'abc';:'def'
>   '*' (4:}) a
> abc
> d*f
>
> This looked odd.  I experimented further.
>
> I know that '4:' will always return a single 4 (rank 0), but upon
> substituting that result, I find:
>
>   '*' (4}) a
> |index error
> |   '*'    (4})a
>
> This makes sense, as 4 tries to address the row 4 of the table (and
> only rows 0 and 1 exist)
>
> The behaviour of u} is as if the array is being ravelled, modified
> using the noun indices, and unravelled.  The behaviour matches:
>
>   ($a)$ '*' (4}) ,a
> abc
> d*f
>
> Am I misunderstanding the intended nature of u}?  The definition in
> the documentation does not mention this pseudo-ravelling, though the
> first example illustrates it.  How do I avoid it happening?  Is it a
> known bug kept for compatibility; I could find no mention in the
> archives?
>
> Related: is there a conventional way to convert between ravelled and
> non-ravelled indexes, for a given array shape?  I would rather not do
> it in 20 characters if I could do it in 5.
>
> --
> src/
> ----------------------------------------------------------------------
> 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

Reply via email to