```{index} single: PDL::Ufunc ``` # PDL::Ufunc ```{pperl-module-badges} PDL::Ufunc ``` Reductions of PDL's ndarrays: sums, products, means, extrema, medians, percentiles, logical and bitwise folds, running sums and products, and sorting. ```perl use PDL; my $m = pdl([3, 1, 2], [9, 7, 8]); print $m->sum, " ", $m->avg, " ", $m->max, "\n"; # 30 5 9 print sumover($m), " ", minimum($m), "\n"; # [6 24] [1 7] print $m->transpose->sumover, "\n"; # [12 8 10] print qsort(pdl(3, 1, 2)), " ", qsorti(pdl(3, 1, 2)), "\n"; # [1 2 3] [1 2 0] my ($min, $max) = $m->minmax; print "$min $max ", cumusumover(pdl(1, 2, 3)), "\n"; # 1 9 [1 3 6] print pct(pdl(1 .. 9), 0.5), " ", medover(pdl(1, 2, 3, 4)), "\n"; # 5 2.5 ``` The functions come in two shapes. The `...over` functions reduce the FIRST dimension and broadcast over the others: a 3x2 matrix gives 2 sums. To reduce another dimension, move it first (`transpose`, `mv`, `xchg`). The whole-array functions (`sum`, `avg`, `min`, `median`, `and`, ...) reduce every value to one, a 0-dim ndarray. Bad values are skipped throughout. This is PDL::Ufunc of PDL 2.106. The kernels are PDL's own, through pperl's engine; upstream's Perl is used unchanged for `minmax`, `minimum_n_ind`/`maximum_n_ind` (the n smallest or largest) and the synonyms `minover`, `maxover`, `minover_ind`, `maxover_ind`, `minover_n_ind`, `maxover_n_ind`, `minmaxover`, `avgover`, `davgover`, `any` and `all`.