rpl=:] - (-/ , 0:)@[ {~ [EMAIL PROTECTED] i. ]  NB. from rpl2a in 
NB. http://www.jsoftware.com/pipermail/programming/2007-July/007303.html

   [temp=. 2 5 ? 10
2 4 0 0 0
4 0 9 7 5

   (0,:_) rpl temp
2 4 _ _ _
4 _ 9 7 5


R.E. Boss


-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Alex Rufon
Verzonden: donderdag 18 september 2008 10:44
Aan: Programming forum
Onderwerp: [Jprogramming] Applying Amend on each row

Hi.

What I want to do is to replace all zero in the matrix with infinity.

This is my solution and it works as expected:
amendEachZero=: dyad define
NB. Get the passed parameters
newval=. x
source=. Y

NB. Loop through each row
for_xyz. source do.
NB. Replace each 0 with a new value
  source=. (newval (I. 0 = xyz)} xyz) xyz_index } source
end.

NB. Return the result
source
)

As you can see, this works:
   [temp=. 2 5 ? 10
5 7 0 0 0
3 6 0 5 4   
   _ amendEachZero temp
5 7 _ _ _
3 6 _ 5 4

But what I really wanted to do was make a tacit definition which would
not require the explicit for_xyz. Loop.

So how do I apply the (I. 0 =) to each row of a 2 dimension matrix, then
use that as an the index to an amend operation? Am I approaching this
problem wrong? 

This is actually an extension of the verb conjunction discussion I
started earlier which actually means ... I still haven't understood how
to use them. :P

Thanks for any help.

r/alex

----------------------------------------------------------------------
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