There are a few other approaches that work here..

One uses amend. You probably should not want to use Item Amend for
this (because the shape of the result is different from the shape of
the argument, and working around that issue gets messy). But amend
consumes three arguments, so to use it tacitly, you should be using a
gerund which specifies how to construct those from the arguments you
supply.

(Also, I'm going to use V instead of v for the name (because v is one
of the reserved argument names which makes it confusing to work with
in some obscure examples).)

For example:

   V=: 1:`[`]}&(10$0)"0
   V 0 1 2
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0

Another approach, though, would be to use { instead of } -- for example:

   V=: {&(=i.10)
   V 0 1 2
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0

And, of course, (repeating Kenneth Lettow's suggestion):

   V=: (i.10)&e."0
   V 0 1 2
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0

That said, one other possibility (hinted at by the "0 in the e.
implementation) would be to use =/

   V=: =/&(i.10)
   V 0 1 2
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0

There's some other variations on these themes...

Thanks,

-- 
Raul
On Mon, Oct 29, 2018 at 2:03 PM Kenneth Lettow <[email protected]> wrote:
>
> Maybe something like this?
>
> v=: (i.10)&e."_ 0
>
> v 1 2 3
>
> 0 1 0 0 0 0 0 0 0 0
>
> 0 0 1 0 0 0 0 0 0 0
>
> 0 0 0 1 0 0 0 0 0 0
>
> v 0 1 2
>
> 1 0 0 0 0 0 0 0 0 0
>
> 0 1 0 0 0 0 0 0 0 0
>
> 0 0 1 0 0 0 0 0 0 0
>
>
>
>
> On Mon, Oct 29, 2018 at 1:57 PM, Lorenz Köhl <[email protected]> wrote:
>
> > Hi,
> >
> > I need a verb to turn a list of numbers between zero and nine
> > into a table where each item is 10$0 except at the place indexed
> > by the input numbers, for example:
> >
> >    v 0 1 2
> >
> > 1 0 0 0 0 0 0 0 0 0
> >
> > 0 1 0 0 0 0 0 0 0 0
> >
> > 0 0 1 0 0 0 0 0 0 0
> >
> > My approach using ammend leaves me puzzled:
> >
> >
> > v=:1&(]})&(10$0)
> >
> > v 1 2 3
> >
> > 1 0 0 0 0 0 0 0 0 0
> >
> > 1 1 0 0 0 0 0 0 0 0
> >
> > 1 1 0 0 0 0 0 0 0 0
> >
> >
> > Here I have to bind two nouns (1 as x and 10$0 as y) to the verb
> >
> > (]}) but maybe that doesn't do what I think it does? The rank of v
> >
> > doesn't seem to matter, it gives the same output, but I know I want
> >
> > it to use 0-cells of the input list.
> >
> >
> > I'd be happy to see what the idiomatic way to do this is, and maybe
> >
> > how to fix my approach.
> >
> >
> > greetings,
> >
> > Lorenz
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
>
> --
> *Kenneth Lettow*
> Director Market Intelligence | Thomas™
> Thomasnet.com <https://www.thomasnet.com> | #ThomasForIndustry
> <https://www.thomasnet.com> <https://www.thomasnet.com>[image: Thomas For
> Industry] <https://www.thomasnet.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

Reply via email to