NAME

PDL::Basic -- Basic utility functions for PDL

DESCRIPTION

This module contains basic utility functions for creating and manipulating piddles. Most of these functions are simplified interfaces to the more flexible functions in the modules PDL::Primitive and PDL::Slices.

SYNOPSIS

use PDL::Basic;

FUNCTIONS

xvals

Fills a piddle with X index values

$x = xvals($somearray);
$x = xvals([OPTIONAL TYPE],$nx,$ny,$nz...);

etc. see 'zeroes'

perldl> print xvals zeroes(5,10)
Dims:  5,10  DLen:  400

[
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
 [0 1 2 3 4]
]

yvals

Fills a piddle with Y index values

$x = yvals($somearray); yvals(inplace($somearray));
$x = yvals([OPTIONAL TYPE],$nx,$ny,$nz...);

etc. see 'zeroes'

perldl> print yvals zeroes(5,10)
Dims:  5,10  DLen:  400

[
 [0 0 0 0 0]
 [1 1 1 1 1]
 [2 2 2 2 2]
 [3 3 3 3 3]
 [4 4 4 4 4]
 [5 5 5 5 5]
 [6 6 6 6 6]
 [7 7 7 7 7]
 [8 8 8 8 8]
 [9 9 9 9 9]
]

zvals

Fills a piddle with Z index values

$x = zvals($somearray); zvals(inplace($somearray));
$x = zvals([OPTIONAL TYPE],$nx,$ny,$nz...);

etc. see 'zeroes'

perldl> print zvals zeroes(3,4,2)
Dims:  3,4,2  DLen:  192

[
 [
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
 ]
 [
  [1 1 1]
  [1 1 1]
  [1 1 1]
  [1 1 1]
 ]
]

xlinvals, ylinvals, zlinvals

X,Y or Z axis values between endpoints. (see xvals,yvals,zvals)

$a = zeroes(100,100);
$x = $a->xlinvals(0.5,1.5); 
$y = $a->ylinvals(-2,-1);
$z = f($x,$y);            # calculate Z for X between 0.5 and 1.5 and
			   # Y between -2 and -1.

xlinvals, ylinvals and zlinvals return a piddle with the same shape as their first argument and linearly scaled values between the two other arguments along the given axis.

hist

Create histogram of a piddle

([$xvals],$hist) = hist($data,[$min,$max,$step]);

- $xvals is returned with the computed bin centres

A nice idiom (with PDL::Graphics::PG) is

bin hist $data;  # Plot histogram
perldl> p $y
[13 10 13 10 9 13 9 12 11 10 10 13 7 6 8 10 11 7 12 9 11 11 12 6 12 7 10 10 10 13]
perldl> $h = hist $y,0,20,1
hist with step 1, min 0 and 21 bins

perldl> p $h
[0 0 0 0 0 0 2 3 1 3 8 4 4 5 0 0 0 0 0 0 0]

sequence

Create array filled with a sequence of values

$a = sequence($b); $a = sequence [OPTIONAL TYPE], @dims;
etc. see 'zeroes'
perldl> p sequence(10)
Dims:  10  DLen:  80
[0 1 2 3 4 5 6 7 8 9]
perldl> p sequence(3,4)
Dims:  12  DLen:  96

[
 [ 0  1  2]
 [ 3  4  5]
 [ 6  7  8]
 [ 9 10 11]
]

rvals

Fills a piddle with radial distance values from some centre.

$r = rvals $piddle,{OPTIONS}; 
$r = rvals [OPTIONAL TYPE],$nx,$ny,...{OPTIONS};
Options:

Centre => [$x,$y,$z...] # Specify centre
Center => [$x,$y.$z...] # synonym.
perldl> print rvals long,7,7,{Centre=>[2,2]}
Dims:  7,7  DLen:  196

[
 [2 2 2 2 2 3 4]
 [2 1 1 1 2 3 4]
 [2 1 0 1 2 3 4]
 [2 1 1 1 2 3 4]
 [2 2 2 2 2 3 4]
 [3 3 3 3 3 4 5]
 [4 4 4 4 4 5 5]
]

axisvals

Fills a piddle with index values on Nth dimension

$z = axisvals ($piddle, $nth);

This is the routine, for which xvals(), yvals() etc are mere shorthands. axisvals() can be used to fill along any dimension.

Note the 'from specification' style (see 'zeroes') is not available here, for obvious reasons.