rpl2a=: ] - (-/ , 0:)@[ {~ {.@[ i. ] 

by Hui from 
http://www.jsoftware.com/pipermail/programming/2007-July/007303.html  is the 
most elegant known (to me).

If x and y are from a small domain (e.g. characters), then rpl3a is faster and 
leaner: http://www.jsoftware.com/pipermail/programming/2007-July/007302.html 

rpl3a=: 4 : 0
 'x0 x1'=. x
 ((x1,a.) {~ (x0,a.) i. ]) y
)


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Gian Medri
(...) 

> 2) Often I encounter the necessity to replace element x by element y in an
> array.
> I solved the problem in an APL fashion such as:
> repl=: 4 : '($y)$ (1{x) (((0{x)=,y)#i.*/$y)},y'  NB. replace x1 in array y by 
> x2
> 
>  This verb works OK for any array, but I wonder if there is a better J-way to 
> do
> it.


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

Reply via email to