in reply to Re^3: matching pdl elements
in thread matching pdl elements

Thank you--the example was very helpful. Here's what I wanted to do (and a possibly inelegant formulation of a solution):
perldl> p $a=sequence(5) [0 1 2 3 4] perldl> p $b=pdl(1,4,9,9,16) [1 4 9 9 16] **** To get the index of values in $a that can be found anywhere in $b +: perldl> $d=which(maximum (($a==$b->dummy)->xchg(0,1))!=0) perldl> p $d [1 4]

Replies are listed 'Best First'.
Re^5: matching pdl elements
by plobsing (Friar) on Sep 14, 2008 at 17:12 UTC
    Holy obfuscation, Batman!

    That seems to work. You could choose to use that (and hopefully leave a comment above it in your script). But you can get rid of some cruft there.

    First, as mentioned before, the dummy dim on $b is arbitrary. Using xchg when you already got to pick the dims is silly.
    which( maximum( ($a->dummy == $b) ) != 0)
    Maximum is a good choice. Like summation, it folds over a dimension in a way that works like logical or. But the inequality is unnecessary. All non-zero values are true. which already handles this.
    which( maximum( $a->dummy == $b ) )
    Thats about as good as any solutions I could give you. You'll still need a comment, but its a little easier on the eyes.

    For comparison purposes, here's the solutions I was expecting:
    # The one I basically handed you. Catches duplicates. $c = which( $a == $b->dummy ) % $a->dim(0); # Switching up the dims. Basically same as above. $c = which( $a->dummy == $b ) / $b->dim(0); # Using summation. Like yours, ignores duplicates. $c = which( sumover( $a->dummy == $b ) );
    They are no more understandable than your solution (once trimmed).