In case it wasn't clear, a 1-D byte piddle can be used instead
of the constant values in my example and PDL will do the looping
for you:

pdl> $table = zeros(byte,256)
pdl> $count = sequence(byte,256)
pdl> for my $shift (0..7) { $table += ( 0x01 & ($count>>$shift) ); }
pdl> p $table
[0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1 2 2 3 2 3 3 4 2 3 3 4 3 4 4 5 1 2 2
3 2 3 3 4 2 3 3 4 3 4 4 5 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 1 2 2 3 2 3
3 4 2 3 3 4 3 4 4 5 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 2 3 3 4 3 4 4 5 3
4 4 5 4 5 5 6 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 1 2 2 3 2 3 3 4 2 3 3 4
3 4 4 5 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5
6 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6 3 4
4 5 4 5 5 6 4 5 5 6 5 6 6 7 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 4 5 5 6 5
6 6 7 5 6 6 7 6 7 7 8]
pdl> $data = floor(256*random(50))->byte
pdl> p $data
[92 114 65 174 8 171 118 108 138 53 182 238 51 163 119 245 101 167 89
148 80 34 219 230 53 51 244 96 8 253 125 94 108 60 113 248 183 120 239
104 69 114 134 175 97 149 4 213 196 245]
pdl> p $table($data)
[4 4 2 5 1 5 5 4 3 4 5 6 4 4 6 6 4 5 4 3 2 2 6 5 4 4 5 2 1 7 6 5 4 4 4
5 6 4 7 3 3 4 3 6 3 4 1 5 3 6]

...and please keep copying the perldl list with your replies so
that other PDL users may benefit from the answers and discussion.

Cheers,
Chris

On Tue, Sep 10, 2013 at 4:20 PM, mraptor <[email protected]> wrote:
> thanks ...forgot I can treat it like 1D table i.e. one loop solution ;)

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

Reply via email to