Discussion:
[Pdl-porters] Operation: 2D-Col x 1D-Col i.e. (per-column normalization)
mraptor
2014-12-18 21:13:59 UTC
Permalink
I have NxN pdl.. then I do this and get one result per column :

$b = sqrt($a(:,0:10)->power(2,0)->sumover)

so far so good ... it produces a list(1d array) ... how do I now do
something like this :

$a(:,0:10) / $b

this wont work of course... what I want to do is to divide every
element in column X to X-th element of $b

axcol / (bxcol,byrow)


thanks

-------| http://ifni.co
Chris Marshall
2014-12-18 23:26:00 UTC
Permalink
You need to make the thread dimensions match in the division.
If you add a dummy dim(0) of size 1 to $b they will match
because dimensions of extent 1 match dimensions of any
extent. Another way is to use dataflow and dimension
reordering. Here is a short pdl2 session showing the two:

pdl> $PDL::doubleformat = '%.2f'; # so it prints even
pdl> p $a = floor(random(15,15)*10); # make a [15,15] pdl
[
[5 3 4 0 7 9 2 0 4 5 1 4 2 0 5]
[9 6 9 9 7 7 1 5 5 3 7 7 4 5 6]
[2 5 0 4 4 2 3 0 3 3 0 9 8 3 0]
[1 4 1 8 7 8 4 9 6 0 4 2 4 2 4]
[7 4 9 7 7 8 7 7 2 3 1 4 2 7 4]
[9 5 8 2 2 9 9 9 6 4 8 5 7 8 9]
[1 9 7 7 6 0 3 3 6 7 3 7 6 8 1]
[7 7 6 8 4 3 3 4 0 8 5 6 5 0 5]
[7 0 0 7 3 8 1 8 0 5 0 4 8 2 9]
[2 9 6 3 9 8 0 3 2 9 4 6 4 2 6]
[7 5 6 1 3 5 6 4 5 6 4 5 4 8 0]
[5 5 0 9 7 4 7 9 7 8 2 7 3 6 9]
[7 5 2 4 6 7 1 3 8 3 4 2 3 6 7]
[4 7 9 3 4 0 1 4 1 8 0 8 4 3 7]
[4 9 4 9 5 8 8 8 0 5 6 4 2 5 3]
]
pdl> p $a->info; # see?
PDL: Double D [15,15]
pdl> $b = $a(:,0:10)->power(2,0)->sumover->sqrt; # compute $b
pdl> p $b->info; # $b is shape [11]
PDL: Double D [11]
pdl> p $a(:,0:10)/$b(*1); # now thread dims
match, [15,11] vs [ 1,11]
[
[0.30 0.18 0.24 0.00 0.43 0.55 0.12 0.00 0.24 0.30 0.06 0.24 0.12 0.00
0.30]
[0.36 0.24 0.36 0.36 0.28 0.28 0.04 0.20 0.20 0.12 0.28 0.28 0.16 0.20
0.24]
[0.13 0.32 0.00 0.26 0.26 0.13 0.19 0.00 0.19 0.19 0.00 0.57 0.51 0.19
0.00]
[0.05 0.20 0.05 0.41 0.36 0.41 0.20 0.46 0.31 0.00 0.20 0.10 0.20 0.10
0.20]
[0.31 0.18 0.40 0.31 0.31 0.36 0.31 0.31 0.09 0.13 0.04 0.18 0.09 0.31
0.18]
[0.33 0.18 0.29 0.07 0.07 0.33 0.33 0.33 0.22 0.15 0.29 0.18 0.25 0.29
0.33]
[0.05 0.41 0.32 0.32 0.27 0.00 0.14 0.14 0.27 0.32 0.14 0.32 0.27 0.37
0.05]
[0.34 0.34 0.29 0.39 0.19 0.15 0.15 0.19 0.00 0.39 0.24 0.29 0.24 0.00
0.24]
[0.34 0.00 0.00 0.34 0.15 0.39 0.05 0.39 0.00 0.24 0.00 0.19 0.39 0.10
0.44]
[0.09 0.41 0.27 0.14 0.41 0.37 0.00 0.14 0.09 0.41 0.18 0.27 0.18 0.09
0.27]
[0.36 0.26 0.31 0.05 0.15 0.26 0.31 0.21 0.26 0.31 0.21 0.26 0.21 0.41
0.00]
]
pdl> $a->(:,0:10)->mv(1,0) /= $b; # now use dataflow
with inplace division
pdl> p $a; # voila!
[
[0.30 0.18 0.24 0.00 0.43 0.55 0.12 0.00 0.24 0.30 0.06 0.24 0.12 0.00
0.30]
[0.36 0.24 0.36 0.36 0.28 0.28 0.04 0.20 0.20 0.12 0.28 0.28 0.16 0.20
0.24]
[0.13 0.32 0.00 0.26 0.26 0.13 0.19 0.00 0.19 0.19 0.00 0.57 0.51 0.19
0.00]
[0.05 0.20 0.05 0.41 0.36 0.41 0.20 0.46 0.31 0.00 0.20 0.10 0.20 0.10
0.20]
[0.31 0.18 0.40 0.31 0.31 0.36 0.31 0.31 0.09 0.13 0.04 0.18 0.09 0.31
0.18]
[0.33 0.18 0.29 0.07 0.07 0.33 0.33 0.33 0.22 0.15 0.29 0.18 0.25 0.29
0.33]
[0.05 0.41 0.32 0.32 0.27 0.00 0.14 0.14 0.27 0.32 0.14 0.32 0.27 0.37
0.05]
[0.34 0.34 0.29 0.39 0.19 0.15 0.15 0.19 0.00 0.39 0.24 0.29 0.24 0.00
0.24]
[0.34 0.00 0.00 0.34 0.15 0.39 0.05 0.39 0.00 0.24 0.00 0.19 0.39 0.10
0.44]
[0.09 0.41 0.27 0.14 0.41 0.37 0.00 0.14 0.09 0.41 0.18 0.27 0.18 0.09
0.27]
[0.36 0.26 0.31 0.05 0.15 0.26 0.31 0.21 0.26 0.31 0.21 0.26 0.21 0.41
0.00]
[5.00 5.00 0.00 9.00 7.00 4.00 7.00 9.00 7.00 8.00 2.00 7.00 3.00 6.00
9.00]
[7.00 5.00 2.00 4.00 6.00 7.00 1.00 3.00 8.00 3.00 4.00 2.00 3.00 6.00
7.00]
[4.00 7.00 9.00 3.00 4.00 0.00 1.00 4.00 1.00 8.00 0.00 8.00 4.00 3.00
7.00]
[4.00 9.00 4.00 9.00 5.00 8.00 8.00 8.00 0.00 5.00 6.00 4.00 2.00 5.00
3.00]
]
Hope this helps,
Chris
$b = sqrt($a(:,0:10)->power(2,0)->sumover)
so far so good ... it produces a list(1d array) ... how do I now do
$a(:,0:10) / $b
this wont work of course... what I want to do is to divide every
element in column X to X-th element of $b
axcol / (bxcol,byrow)
thanks
-------| http://ifni.co
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
Loading...