If you're looking to extract individual elements as normal Perl scalars, use at
instead of slice
:
pdl> $pdl = random(4,4)
pdl> p $pdl->at(0,0) + $pdl->at(1,0)
0.288796754210711
pdl> p ref \($pdl->at(0,0) + $pdl->at(1,0))
SCALAR
To convert the entire ndarray object into nested Perl arrays, use unpdl
pdl> $aoa = random(4,4)->unpdl;
pdl> p ref $aoa
ARRAY
pdl> p ref $aoa->[0]
ARRAY
Note that the indexing of elements in the Perl arrays is the transverse of that done in the ndarray objects. For example,
pdl> p $pdl->at(1,0)
0.111869023064209
pdl> p $aoa->[1][0] # wrong
0.954887281829823
pdl> p $aoa->[0][1] # correct
0.111869023064209