Hi all !

About the problem I want to solve.

Generally you compare some arrays and you want to replace part of one of them with info from the other or from some other array of the same dimensions?

I found a solution not using Amend:

NB. x and y are arrays of the same rank

NB. q is a boolean, also of this rank

NB. The expression merges x and y.

NB. Where q is TRUE it picks from y, otherwise x

NB. q {"0 1 x,"0 y

1 2 3(< {"0 1 [ ,"0 ])2 2 2
2 2 3


A similar solution using Amend. I'm sure it can be improved, just I didn't do it yet. I didn't try it for the general case.


NB. Amend

NB. x (v0`v1`v2)} y ↔ (x v0 y) (x v1 y)} (x v2 y)

1 2 3(> # [)`(> # [: i. [: $ ])`(])}2 2 2
2 2 3


I think what makes Amend tricky is that you(as Ric says) need three inputs. To get them into the tacit expression you have to put two of them together in one noun.


There are probably other solutions using sort.


Trying the same expression with a version of Raul's Amend:

amende=: (0 {:: [)`(1 {:: [)`]}

1 2 3((> (# ; [: (# i.&$) [ ) [) amende ])2 2 2

2 2 3


Some bug causes Thunderbird to reformat my mails. Hope you get them right.

I'm looking for something more general than this :)

1 2 3 >. 2 2 2

2 2 3


/Erling

On 2014-07-07 05:58, Raul Miller wrote:
Since it'w nagging at me (and this is still unteted code :/), here's
what I currently think i should have said:
    amend=: (0:{::])`(1:{::])`(2:{::])}~

The trailing ~ because I need the dyad from the resulting verb, and
the trailing ] on each because those verbs need to ignore one of the
resulting arguments.

Sadly, my fingers (and "quick memory") keep forgetting this.

Thanks,


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to