On Wed, Jun 23, 2010 at 9:23 PM, Chris Marshall <[email protected]> wrote:
> On 6/23/2010 8:43 PM, P Kishor wrote: > > > > That seems the various methods don't seem to work analogously. For > > example, $a->reshape() changes $a, but $b->dummy() doesn't change $b. > > I believe reshape works in place. I would prefer that it > work otherwise unless inplace is requested. You are right > about the inconsistency.... > > > [ > > [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 > > $x = $a((2),:) > $x .= floor($x->random * 10 + 20) > > > 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] > > ] > > (int(rand(10)) + 20) is all perl scalar operations. > I think you may be confusing operations on piddles with > standard scalar perl stuff. > > > 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 > > int() is a perl built-in function. See perldoc -f int for > what it does. HINT: it doesn't know anything about piddles. > > > Wha!!! What happened there? Why does $a = $a * 100 multiply every > > element in $a by 100, but int($a) converts $a to 0? > This gave me a headache lately myself. You're looking for the type conversion function. Turns out that is called... short! As in, short int, or long for long int. Yeah, I didn't guess that either. Even apropos fell short for me. (Ha!) To find this type conversion, I found the documentation for double piddle conversion and scrolled up. :-) Hope that helps. FYI, I try to hang around the IRC channel during my work day (and your work day - I live in Urbana, IL). So if you have questions like this and want quick feedback, you can always check if run4flat is on #pdl on irc.perl.org. David -- Sent via my carrier pigeon.
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
