The standard idiom for doing this is array =: (array = 0)} array ,: _
If array is big, you get a big boost from performing the update in place. To do that, you have to write zeros =. array = 0 inf =. ($array) $ _ array =: zeros} array ,: inf Henry Rich > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Alex Rufon > Sent: Thursday, September 18, 2008 4:44 AM > To: Programming forum > Subject: [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
