[Jprogramming] amend question
Sherlock, Ric
R.G.Sherlock at massey.ac.nz
Mon Jan 25 14:12:09 HKT 2010
> From: Sherlock, Ric
> > From: Brian Schott
> >
> > I get these results from amend, but ...
> >
> > (2 1$70 90) (2 1 $0 1;1 2) }"1 2 i. 2 3
> > 0 70 2
> > 3 4 70
> >
> > 0 90 2
> > 3 4 90
> >
> > I want the results below. How can I get the results
> > I desire changing only the shapes on the left of } or the
> > rank of } ? I can even use a solution that reshapes the
> > right hand argument using the shapes of the other arrays or
> > one that translates the right hand argument.
> >
> > 0 70 2
> > 3 4 5
> >
> > 0 1 2
> > 3 4 90
>
> I don't think you can get what you want by only changing x & m.
> The major stumbling block is that the whole of m will apply to every
> application of x to y.
> I think you want to end up with something like the following:
>
> (70 90) (0 0 1;1 1 2)} (2#,: i.2 3)
> 0 70 2
> 3 4 5
>
> 0 1 2
> 3 4 90
>
> Starting with
> x=: 70 90
> y=: i.2 3
>
> x [`((0 0 1;1 1 2)"_)`(#@[ # ,:@])} y
> 0 70 2
> 3 4 5
>
> 0 1 2
> 3 4 90
>
> Now you just need a verb that gives you the indicies...
If you have a list of the indicies that you need to replace with an item of x in the respective copies of y:
m=: 0 1 ,: 1 2
Then:
x [`(m ;/@:,.~ i.@#@[)`(#@[ # ,:@])} y
0 70 2
3 4 5
0 1 2
3 4 90
Of course you can do instead:
midx=: ;/ (i.#x) ,. m
y2=: (#x) # ,: y
x midx} y2
0 70 2
3 4 5
0 1 2
3 4 90
More information about the Programming
mailing list