in reply to Re^2: matching pdl elements
in thread matching pdl elements
Turns out the indices of values in $c->flat correspond to their position in $c using the equation:perldl> $a = sequence(5) perldl> $b = pdl [1,4,9,16] perldl> p $c = $a == $b->dummy [ [0 1 0 0 0] [0 0 0 0 1] [0 0 0 0 0] [0 0 0 0 0] ] # This matrix's horizontal dim corresponds to $a # and the vertical to $b. # In other words, $c->($x,$y) is $a->($x) == $b->($y) perldl> p which $c [1 9] # Confusing results? Think about the matrix above. # Can you see a pattern? # I mentioned 'flatten' in an earlier post. That was a clue. perldl>p $c->flat [0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0] # This looks like all the rows of the matrix concatenated. # And look, the values at 1 and 9 are the only true ones
And that is related to $a and $b like so:$c_flat_pos = $c_dim_0_pos + $c_dim_1_pos * $sizeof_c_dim_0
Note that the term $index_in_a will alway be less than $sizeof_a and that the term ($index_in_b * $sizeof_$a) will alway be a multiple of $sizeof_a. In other words, we're looking for the remainder of which $c when divided by $a->dim(0). This is known as the modulo operation.$c_flat_pos = $index_in_a + ($index_in_b * $sizeof_a)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: matching pdl elements
by Blue_eyed_son (Sexton) on Sep 14, 2008 at 16:35 UTC | |
by plobsing (Friar) on Sep 14, 2008 at 17:12 UTC |