index in

index in

Post by TikkaN » Tue, 18 Oct 2005 06:18:29


I have two arrays whose rows are uniquely identified by the combination
of two columns. I need to find the row-indices in ARRAY1 of the rows
matching those in ARRAY2.

I am using the following code to provde me with the index.
This works fine for smaller arrays but when I get up to array sizes of
10000 rows or so, execution is noticibally slow.
({enclose[2]ARRAY1[;idCol1 idCol2]) {iota} {enclose}[2]ARRAY2[;idCol1
idCol2]

Are there other/better/faster ways of doing this?
 
 
 

index in

Post by Curtis A. » Tue, 18 Oct 2005 07:31:20

Do column 1 and column 2 have numbers? If they have characters, the
current Workstation APL2 has an external routine RF (RowFind).

For numbers I wrote an RIOTA (row iota) function that's fairly fast,
but it's over 20 lines long.

The general approach is to catenate the two arrays (In your example,
the two columns selected from your larger arrays) one above the other
and sort the combined array. Muck around for a while and crank out
either the index of the row of the left argument following the
corresponding row of the right argument or {quadIO} plus the number of
rows of the left argument.

Thanks for asking. I hope a better way is suggested! Curtis Jones

 
 
 

index in

Post by David Lieb » Tue, 18 Oct 2005 12:12:25

Or if the matrices have numbers from 0 to 2*32 - 1, you could use QuadAF to
convert the numbers to characters and then use RowFind.

Or if the matrices have rational numbers, you could convert them to
characters using ATR and then use RowFind.

David Liebtag
IBM APL Products and Services
 
 
 

index in

Post by Bjn Helgas » Tue, 18 Oct 2005 23:18:33

In J

www.jsoftware.com

]ARRAY1=.4 3$1 2 3 3 4 5 6 7 8 9 10 11
1 2 3
3 4 5
6 7 8
9 10 11

]ARRAY2=.4 3$1 2 3 6 7 8 3 4 5 9 10 11
1 2 3
6 7 8
3 4 5
9 10 11

(0 1{"1 ARRAY1) i. (0 1{"1 ARRAY2)
0 2 1 3
 
 
 

index in

Post by Ted Edward » Wed, 19 Oct 2005 03:10:32


Since the OP asked a question that appears to refer to APL2, I tried
your solution. I typed it in and all I got is a SYNTAX ERROR. Not very
helpful at all. Did you try it before posting it.

Ted