Thanks Chris, thanks so much. After using Perl for a while, just when I thought I started getting a hang of it, in comes PDL. Its like learning a brand new language. Your and others' answers to all my novice questions really help in learning this new language.
I am writing a super-beginners manual, really documenting my own baby steps. Hopefully, it will become something I can share with others, and someone else may benefit from it as well. A few specific responses below. 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.... > Yes, there are a few more. For example, in FastRaw, the writefraw command is writefraw($pdl,"fname"); while in FlexRaw, the analogous writeflex command is $hdr = writeflex($file, $pdl1, $pdl2,...) >From the docs, FlexRaw is made to be a smarter version of FastRaw, but reverses the order of $pdl and filename. There are others as well. >> [ >> [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) Ok. So the above is very interesting. $x is just a reference to the 3rd column in $a (the column marked with 'x'). Then you modify $x, which modifies $a. So, is this the normal idiom for wanting to modify a part of a piddle? Create a reference to the part you want to modify. That reference is a piddle. Then, modify that reference piddle which in turn will modify the referent piddle. What if I wanted to apply a custom function to $x? How would I apply my_func() to $x? > >> 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. > Well, I wasn't really confusing operation on piddle with the perl function int(). I was confused about how to apply int() to a piddle. Now I have learned that I can't. So, while I can do '$a = $a * 4' whereby every element of $a is multiplied by 4, I can't convert every element of $a to int() using the perl int() function. Yet, funnily, I can do sin($a), and that works. That, to me, seems inconsistent. >> 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? > > Cheers, > Chris > > _______________________________________________ > Perldl mailing list > [email protected] > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science ======================================================================= _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
