The tacit definition is WAY faster than using a for loop on large amount
of data.
   M=: ((1024*1024),4)[EMAIL PROTECTED] 
   ts 'amendZeros M'
0.11664729735203776 71304192
   ts '_ amendEachZero M'
5.4896494526538984 67112768
   
Hmmm. This really is a big incentive to learning tacit programming.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Alex Rufon
Sent: Thursday, September 18, 2008 7:07 PM
To: Programming forum
Subject: RE: [Jprogramming] Applying Amend on each row

Hi,

It took me a while to understand what you were doing.

If parse the code manually, this is what I'll get:
   M
6 5 9 2
4 9 0 7
0 4 6 8
3 8 1 2
   M - (0 i. M) { _ 0
 6 5  9 2
 4 9 __ 7
__ 4  6 8
 3 8  1 2

Hahahah. It took me a while to get it. 

Thanks.

r/alex

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of R.E. Boss
Sent: Thursday, September 18, 2008 5:22 PM
To: 'Programming forum'
Subject: RE: [Jprogramming] Applying Amend on each row

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