http://www.perlmonks.org?node_id=917017


in reply to Re^2: Performance problem with Clone Method
in thread Performance problem with Clone Method

BrowserUK, you don't think this is actually a problem, do you? PDL is a very mature Perl extension that handles high dimensional data sets very nicely. In fact (surprise!) there's more than one way to do it. At the moment, I believe the best documentation for beginners is the Matlab or Scilab migration guides. They say that PDL::QuickStart is a better place to start, but I humbly disagree. See http://pdl.perl.org/?docs=Tutorials&title=PDL::Tutorials for the (short) list of tutorials available.

To answer your specific question, suppose you have a 2x4 piddle, perhaps created with the sequence command. A snippet of your code might look like this:

my $pdl = sequence(2,4);

If you wanted to modify the (0,3) element of the array (first column, last row), you would use NiceSlice and the .= notation like so:

$pdl(0,3) .= -4;

A full working example would look like this:

use strict; use warnings; use PDL; use PDL::NiceSlice; my $pdl = sequence(2,4); print "$pdl\n"; $pdl(0,3) .= -4; print "$pdl\n";

The output looks like this:

[ [0 1] [2 3] [4 5] [6 7] ] [ [ 0 1] [ 2 3] [ 4 5] [-4 7] ]

Edit: revised the opening paragraph to be more useful

Edit2: re-revised the opening paragraph to be even more useful

Edit3: used code tags instead of pre tags for example code and ouput