Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to iterate through a PDL piddle?

by zentara (Archbishop)
on Mar 10, 2011 at 14:31 UTC ( [id://892434]=note: print w/replies, xml ) Need Help??


in reply to How to iterate through a PDL piddle?

You need a dog, not puppies. :-) Does this work?
#!/usr/bin/perl use strict; use warnings; use PDL::LiteF; #dog dosn't work on huge values my $u = pdl [1,2,3,4]; my $dim = 4; print join "\t", $u->dog; print "\n";

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: How to iterate through a PDL piddle?
by arrac (Initiate) on Mar 11, 2011 at 07:36 UTC
    Thanks @zentara. It works! I can't believe that it works though. There should be a more obvious way like  $u->list which gives an array reference. Or a custom iterator on a piddle which can replace  foreach.
      If you feel the urge to use an iterator in PDL, quite often that is a sign you could instead use "array programming" type constructs (see https://en.wikipedia.org/wiki/Array_programming), which lets all the processing be done inside the fast C loops, rather than going backwards and forwards between Perl and PDL.
      Errr..... there IS a 'list' function $u->list acts the same as $u->dog except list breaks the piddle up into individual elements while dog breaks it up into N-1-dimensional slices. In this particular case, where $u is one-dimensional, $u->list is identical to $u->dog
        • dog returns a list of PDL slices, as Dima says, so a 2,3,4 ndarray dog-ed would return 4 ndarrays each dimensioned 2,3 (and as they're "slices", updates to them would be reflected in the original ndarray)
        • list returns the ndarray flattened (so the whole thing in a single flat list) as Perl scalars, so a 2,3,4 would be a list of 24 Perl scalars
        • unpdl (as of 2.006 from 2013, as provided by the mighty Joel Berger), which returns the ndarray as an array-ref with the same (possibly nested) structure as the input ndarray.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://892434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 18:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found