1Reduce(3)             User Contributed Perl Documentation            Reduce(3)
2
3
4

NAME

6       PDL::Reduce -- a "reduce" function for PDL
7

DESCRIPTION

9       Many languages have a "reduce" function used to reduce the rank of an
10       N-D array by one. It works by applying a selected operation along a
11       specified dimension. This module implements such a function for PDL by
12       providing a simplified interface to the existing projection functions
13       (e.g. "sumover", "maximum", "average", etc).
14

SYNOPSIS

16        use PDL::Reduce;
17        $x = sequence 5,5;
18        # reduce by adding all
19        # elements along 2nd dimension
20        $y = $x->reduce('add',1);
21        @ops = $x->canreduce; # return a list of all allowed operations
22

FUNCTIONS

24   reduce
25       reduce dimension of piddle by one by applying an operation along the
26       specified dimension
27
28        $x = sequence 5,5;
29        # reduce by adding all
30        # elements along 2nd dimension
31        $y = $x->reduce('add',1);
32        $y = $x->reduce('plus',1);
33        $y = $x->reduce('+',1);     # three ways to do the same thing
34
35       [ As an aside: if you are familiar with threading you will see that
36       this is actually the same as
37
38        $y = $x->mv(1,0)->sumover
39
40       ]
41
42       NOTE: You should quote the name of the operation (1st arg) that you
43       want "reduce" to perform. This is important since some of the names are
44       identical to the names of the actual PDL functions which might be
45       imported into your namespace. And you definitely want a string as
46       argument, not a function invocation! For example, this will probably
47       fail:
48
49         $y = $x->reduce(avg,1); # gives an error from invocation of 'avg'
50
51       Rather use
52
53         $y = $x->reduce('avg',1);
54
55       "reduce" provides a simple and unified interface to the projection
56       functions and makes people coming from other data/array languages
57       hopefully feel more at home.
58
59        $result = $pdl->reduce($operation [,@dims]);
60
61       "reduce" applies the named operation along the specified dimension(s)
62       reducing the input piddle dimension by as many dimensions as supplied
63       as arguments. If the dimension(s) argument is omitted the operation is
64       applied along the first dimension. To get a list of valid operations
65       see canreduce.
66
67       NOTE - new power user feature: you can now supply a code reference as
68       operation to reduce with.
69
70         # reduce by summing over dims 0 and 2
71         $result = $pdl->reduce(\&sumover, 0, 2);
72
73       It is your responsibility to ensure that this is indeed a PDL
74       projection operation that turns vectors into scalars!  You have been
75       warned.
76
77   canreduce
78       return list of valid named "reduce" operations Some common operations
79       can be accessed using a number of names, e.g. '+', "add" and "plus" all
80       sum the elements along the chosen dimension.
81
82         @ops = PDL->canreduce;
83
84       This list is useful if you want to make sure which operations can be
85       used with "reduce".
86

AUTHOR

88       Copyright (C) 2000 Christian Soeller (c.soeller@auckland.ac.nz). All
89       rights reserved. There is no warranty. You are allowed to redistribute
90       this software / documentation under certain conditions. For details,
91       see the file COPYING in the PDL distribution. If this file is separated
92       from the PDL distribution, the copyright notice should be included in
93       the file.
94
95
96
97perl v5.32.0                      2020-09-17                         Reduce(3)
Impressum