On Tue, 17 Feb 2009 15:56:56 -0700
Craig DeForest <[email protected]> wrote:

>Hey, nice one, Derek....
>
>Er, you can also use the threading engine:
>
>       perldl> ($n,$m) = (3,2);
>       perldl> ($a,$b) = map { sequence($_) } ($n,$m);
>       perldl> $c = cat($a->(:,*2), $b->(*3,:))->clump(2)->mv(-1,0);
>       perldl> print " a=$a \n b=$b \n c=$c \n";
>        a=[0 1 2]
>        b=[0 1]
>        c=
>       [
>        [0 0]
>        [1 0]
>        [2 0]
>        [0 1]
>        [1 1]
>        [2 1]
>       ]
>This works by padding each array with a dummy dimension: $a->(:,*3) is  
>a 2x3-PDL, as is $b->(*2,:).  Catting them together gives a 2x3x2-PDL,  
>whose 0th dim runs across elements of $a, whose 1st dim runs across  
>elements of $b, and whose 2nd dim runs between the $a and $b pdls.  
>Clumping the first two dimensions gives a 6x2 PDL whose 0th dim runs  
>across index and whose 1st dim runs between $a and $b.  The final mv  
>changes it to a 2x6 pdl, which is what you asked for.
>
>This sort of operation (padding dummied variables) is related to the  
>outer product.  In fact, outer product can be implemented as:
>
>       sub outer {
>        my ($a,$b)=...@_;
>        return $a->(:,*($b->dim(0))) * $b->(*($a->dim(0)),:);
>       }
>
>The difference is that, instead of multiplication, we're doing  
>assembly of vectors.
>
>Best,
>Craig
WoW Craig, I am just a casual PDL reader, but that post was a reminder
of just how smart you guys really are. :-)

zentara

-- 
I'm not really a human, but I play one on earth.
http://www.zentara.net/~zentaran/My_Petition_to_the_Great_Cosmic_Conciousness.html
 

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to