Hello patient PDLers,

Please bear with me and this long email (and, feel free to direct me
to a better venue, if there is one).

perldl> $a = sequence 2,3
perldl> p $a
[
 [0 1]
 [2 3]
 [4 5]
]

So, now I discover that $a really should have been (2,4), so

perldl> $a->reshape(2,4)
perldl> p $a
[
 [0 1]
 [2 3]
 [4 5]
 [0 0]
]

I am happy. But, my boss comes in and says, it really should be (3,4)
with a 0 in the third place in every element in the second dimension.
So

perldl> $a->reshape(3,4)
perldl> p $a
[
 [0 1 2]
 [3 4 5]
 [0 0 0]
 [0 0 0]
]

Oh no! I really wanted

[
 [0 1 0]
 [2 3 0]
 [4 5 0]
 [0 0 0]
]

Now what to do? So, I read up on dummy

perldl> $b = sequence 3
perldl> p $b
[0 1 2]
perldl> $b->dummy(0,3)
perldl> p $b
[0 1 2]

Whaa! What happened there? I follow the docs

perldl> p sequence(3)->dummy(0,3)
[
 [0 0 0]
 [1 1 1]
 [2 2 2]
]
perldl> $c = $b->dummy(0,3)
perldl> p $c
[
 [0 0 0]
 [1 1 1]
 [2 2 2]
]

Yup, that works, but two things -- what the heck did dummy do? And,
why is $b not changed in place.

perldl> p $b
[0 1 2]

That seems the various methods don't seem to work analogously. For
example, $a->reshape() changes $a, but $b->dummy() doesn't change $b.
That is not very intuitive. Ok, so, I want to change

[
 [0 1]
 [2 3]
 [4 5]
 [0 0]
]

to

[
 [0 1 x]
 [2 3 x]
 [4 5 x]
 [0 0 x]
]

Where 'x' is a custom value. For example, I want a 0 for every 'x', or
I want a random number between 20 and 30 for every 'x'. How do I do
that? I know there is the 'random' method. But that creates a new
piddle with random values between 0 and 1. So, I tried a different
tactic

perldl> $a = ones 2,3
perldl> p $a
[
 [1 1]
 [1 1]
 [1 1]
]
perldl> $a = $a * (int(rand(10)) + 20)
perldl> p $a
[
 [25 25]
 [25 25]
 [25 25]
]

No. I didn't want the random integer generated and then every value in
$a multiplied by it. I wanted every value to be multiplied by a
different random integer between 20 and 30. How do I do that?

I fiddled a bit more with 'random'

perldl> $a = random 2,3
perldl> p $a

[
 [  0.22621636   0.72198009]
 [  0.63921956   0.41760895]
 [0.0059526254   0.90491115]
]
perldl> $a = $a * 100
perldl> p $a
[
 [ 22.621636  72.198009]
 [ 63.921956  41.760895]
 [0.59526254  90.491115]
]
perldl> $a = int($a)
perldl> p $a
0

Wha!!! What happened there? Why does $a = $a * 100 multiply every
element in $a by 100, but int($a) converts $a to 0?

-- 
Puneet Kishor

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

Reply via email to