Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate through a Perl PDL piddle?

Tags:

perl

pdl

The closest I got to was something like

use PDL;
my $u = pdl [1,2,3,4];
my $dim = 4;
for(my $i=0; $i<$dim; $i++)
{
  print $u->flat->index($i), "\n";
}

Also as I can convert [1,2,3,4] to piddle $u, can I get back a list (or a list of lists for a matrix) from $u?

like image 592
arrac Avatar asked Feb 25 '23 21:02

arrac


1 Answers

With the wisdom from the monks, I found the answer: http://perlmonks.org/index.pl?node_id=892201

Thought I'd share it here in my original question. The above code can be rewritten as:

use PDL;
my $u = pdl [1,2,3,4];
foreach ($u->dog)
{
  print $_, "\n";
}

The wisdom came with a disclaimer that dog() works only on small piddles (object).

like image 79
arrac Avatar answered Mar 05 '23 02:03

arrac