UfuncSection: User Contributed Perl Documentation (3)Updated: 2004-06-15 |
UfuncSection: User Contributed Perl Documentation (3)Updated: 2004-06-15 |
The PDL::Reduce module provides an alternative interface to many of the functions in this module.
use PDL::Ufunc;
Signature: (a(n); int+ [o]b())
Project via product to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the product along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = prodover($b);
$spectrum = prodover $image->xchg(0,1)
Signature: (a(n); double [o]b())
Project via product to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the product along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = dprodover($b);
$spectrum = dprodover $image->xchg(0,1)
Unlike prodover, the calculations are performed in double precision.
Signature: (a(n); int+ [o]b(n))
Cumulative product
This function calculates the cumulative product along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
The sum is started so that the first element in the cumulative product is the first element of the parameter.
$a = cumuprodover($b);
$spectrum = cumuprodover $image->xchg(0,1)
Signature: (a(n); double [o]b(n))
Cumulative product
This function calculates the cumulative product along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
The sum is started so that the first element in the cumulative product is the first element of the parameter.
$a = cumuprodover($b);
$spectrum = cumuprodover $image->xchg(0,1)
Unlike cumuprodover, the calculations are performed in double precision.
Signature: (a(n); int+ [o]b())
Project via sum to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the sum along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = sumover($b);
$spectrum = sumover $image->xchg(0,1)
Signature: (a(n); double [o]b())
Project via sum to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the sum along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = dsumover($b);
$spectrum = dsumover $image->xchg(0,1)
Unlike sumover, the calculations are performed in double precision.
Signature: (a(n); int+ [o]b(n))
Cumulative sum
This function calculates the cumulative sum along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
The sum is started so that the first element in the cumulative sum is the first element of the parameter.
$a = cumusumover($b);
$spectrum = cumusumover $image->xchg(0,1)
Signature: (a(n); double [o]b(n))
Cumulative sum
This function calculates the cumulative sum along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
The sum is started so that the first element in the cumulative sum is the first element of the parameter.
$a = cumusumover($b);
$spectrum = cumusumover $image->xchg(0,1)
Unlike cumusumover, the calculations are performed in double precision.
Signature: (a(n); int+ [o]b())
Project via or to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the or along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = orover($b);
$spectrum = orover $image->xchg(0,1)
Signature: (a(n); int+ [o]b())
Project via bitwise and to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the bitwise and along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = bandover($b);
$spectrum = bandover $image->xchg(0,1)
Signature: (a(n); int+ [o]b())
Project via bitwise or to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the bitwise or along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = borover($b);
$spectrum = borover $image->xchg(0,1)
Signature: (a(n); int+ [o]b())
Project via == 0 to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the == 0 along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = zcover($b);
$spectrum = zcover $image->xchg(0,1)
Signature: (a(n); int+ [o]b())
Project via and to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the and along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = andover($b);
$spectrum = andover $image->xchg(0,1)
Signature: (a(n); int+ [o]b())
Project via integral to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the integral along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = intover($b);
$spectrum = intover $image->xchg(0,1)
Notes:
For "n > 3", these are all "O(h^4)" (like Simpson's rule), but are integrals between the end points assuming the pdl gives values just at these centres: for such `functions', sumover is correct to O(h), but is the natural (and correct) choice for binned data, of course.
Signature: (a(n); int+ [o]b())
Project via average to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the average along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = average($b);
$spectrum = average $image->xchg(0,1)
Signature: (a(n); double [o]b())
Project via average to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the average along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = daverage($b);
$spectrum = daverage $image->xchg(0,1)
Unlike average, the calculation is performed in double precision.
Signature: (a(n); [o]b(); [t]tmp(n))
Project via median to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the median along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = medover($b);
$spectrum = medover $image->xchg(0,1)
Signature: (a(n); [o]b(); [t]tmp(n))
Project via oddmedian to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the oddmedian along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = oddmedover($b);
$spectrum = oddmedover $image->xchg(0,1)
The median is sometimes not a good choice as if the array has an even number of elements it lies half-way between the two middle values - thus it does not always correspond to a data value. The lower-odd median is just the lower of these two values and so it ALWAYS sits on an actual data value which is useful in some circumstances.
Signature: (a(n); p(); [o]b(); [t]tmp(n))
Project via percentile to N-1 dimensions
This function reduces the dimensionality of a piddle by one by finding the specified percentile (p) along the 1st dimension. The specified percentile must be between 0.0 and 1.0. When the specified percentile falls between data points, the result is interpolated.
By using xchg etc. it is possible to use any dimension.
$a = pctover($b, $p);
$spectrum = pctover $image->xchg(0,1) $p
Signature: (a(n); p(); [o]b(); [t]tmp(n))
Project via percentile to N-1 dimensions
This function reduces the dimensionality of a piddle by one by finding the specified percentile along the 1st dimension. The specified percentile must be between 0.0 and 1.0. When the specified percentile falls between two values, the nearest data value is the result.
By using xchg etc. it is possible to use any dimension.
$a = oddpctover($b, $p);
$spectrum = oddpctover $image->xchg(0,1) $p
$x = pct($data, $pct);
$x = oddpct($data, $pct);
$x = avg($data);
$x = sum($data);
$x = prod($data);
$x = davg($data);
$x = dsum($data);
$x = dprod($data);
$x = zcheck($data);
$x = and($data);
$x = band($data);
$x = or($data);
$x = bor($data);
$x = min($data);
$x = max($data);
$x = median($data);
$x = oddmedian($data);
Useful in conditional expressions:
if (any $a>15) { print "some values are greater than 15\n" }
Useful in conditional expressions:
if (all $a>15) { print "all values are greater than 15\n" }
($mn, $mx) = minmax($pdl);
This routine does not thread over the dimensions of $pdl; it returns the minimum and maximum values of the whole array. See minmaximum if this is not what is required. The two values are returned as Perl scalars similar to min/max.
perldl> $x = pdl [1,-2,3,5,0] perldl> ($min, $max) = minmax($x); perldl> p "$min $max\n"; -2 5
Signature: (a(n); [o]b(n))
Quicksort a vector into ascending order.
print qsort random(10);
Signature: (a(n); int [o]indx(n))
Quicksort a vector and return index of elements in ascending order.
$ix = qsorti $a; print $a->index($ix); # Sorted list
Signature: (a(n,m); [o]b(n,m))
Sort a list of vectors lexicographically.
The 0th dimension of the source piddle is dimension in the vector; the 1st dimension is list order. Higher dimensions are threaded over.
print qsortvec pdl([[1,2],[0,500],[2,3],[4,2],[3,4],[3,5]]); [ [ 0 500] [ 1 2] [ 2 3] [ 3 4] [ 3 5] [ 4 2] ]
Signature: (a(n); [o]c())
Project via minimum to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the minimum along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = minimum($b);
$spectrum = minimum $image->xchg(0,1)
Signature: (a(n); int [o] c())
Like minimum but returns the index rather than the value
Signature: (a(n); int[o]c(m))
Returns the index of "m" minimum elements
Signature: (a(n); [o]c())
Project via maximum to N-1 dimensions
This function reduces the dimensionality of a piddle by one by taking the maximum along the 1st dimension.
By using xchg etc. it is possible to use any dimension.
$a = maximum($b);
$spectrum = maximum $image->xchg(0,1)
Signature: (a(n); int [o] c())
Like maximum but returns the index rather than the value
Signature: (a(n); int[o]c(m))
Returns the index of "m" maximum elements
Signature: (a(n); [o]cmin(); [o] cmax(); int [o]cmin_ind(); int [o]cmax_ind())
Find minimum and maximum and their indices for a given piddle;
perldl> $a=pdl [[-2,3,4],[1,0,3]] perldl> ($min, $max, $min_ind, $max_ind)=minmaximum($a) perldl> p $min, $max, $min_ind, $max_ind [-2 0] [4 3] [0 1] [2 2]
See also minmax, which clumps the piddle together.