1Ufunc(3) User Contributed Perl Documentation Ufunc(3)
2
3
4
6 PDL::Ufunc - primitive ufunc operations for pdl
7
9 This module provides some primitive and useful functions defined using
10 PDL::PP based on functionality of what are sometimes called ufuncs (for
11 example NumPY and Mathematica talk about these). It collects all the
12 functions generally used to "reduce" or "accumulate" along a dimension.
13 These all do their job across the first dimension but by using the
14 slicing functions you can do it on any dimension.
15
16 The PDL::Reduce module provides an alternative interface to many of the
17 functions in this module.
18
20 use PDL::Ufunc;
21
23 prodover
24
25 Signature: (a(n); int+ [o]b())
26
27 Project via product to N-1 dimensions
28
29 This function reduces the dimensionality of a piddle by one by taking
30 the product along the 1st dimension.
31
32 By using xchg etc. it is possible to use any dimension.
33
34 $a = prodover($b);
35
36 $spectrum = prodover $image->xchg(0,1)
37
38 dprodover
39
40 Signature: (a(n); double [o]b())
41
42 Project via product to N-1 dimensions
43
44 This function reduces the dimensionality of a piddle by one by taking
45 the product along the 1st dimension.
46
47 By using xchg etc. it is possible to use any dimension.
48
49 $a = dprodover($b);
50
51 $spectrum = dprodover $image->xchg(0,1)
52
53 Unlike prodover, the calculations are performed in double precision.
54
55 cumuprodover
56
57 Signature: (a(n); int+ [o]b(n))
58
59 Cumulative product
60
61 This function calculates the cumulative product along the 1st dimen‐
62 sion.
63
64 By using xchg etc. it is possible to use any dimension.
65
66 The sum is started so that the first element in the cumulative product
67 is the first element of the parameter.
68
69 $a = cumuprodover($b);
70
71 $spectrum = cumuprodover $image->xchg(0,1)
72
73 dcumuprodover
74
75 Signature: (a(n); double [o]b(n))
76
77 Cumulative product
78
79 This function calculates the cumulative product along the 1st dimen‐
80 sion.
81
82 By using xchg etc. it is possible to use any dimension.
83
84 The sum is started so that the first element in the cumulative product
85 is the first element of the parameter.
86
87 $a = cumuprodover($b);
88
89 $spectrum = cumuprodover $image->xchg(0,1)
90
91 Unlike cumuprodover, the calculations are performed in double preci‐
92 sion.
93
94 sumover
95
96 Signature: (a(n); int+ [o]b())
97
98 Project via sum to N-1 dimensions
99
100 This function reduces the dimensionality of a piddle by one by taking
101 the sum along the 1st dimension.
102
103 By using xchg etc. it is possible to use any dimension.
104
105 $a = sumover($b);
106
107 $spectrum = sumover $image->xchg(0,1)
108
109 dsumover
110
111 Signature: (a(n); double [o]b())
112
113 Project via sum to N-1 dimensions
114
115 This function reduces the dimensionality of a piddle by one by taking
116 the sum along the 1st dimension.
117
118 By using xchg etc. it is possible to use any dimension.
119
120 $a = dsumover($b);
121
122 $spectrum = dsumover $image->xchg(0,1)
123
124 Unlike sumover, the calculations are performed in double precision.
125
126 cumusumover
127
128 Signature: (a(n); int+ [o]b(n))
129
130 Cumulative sum
131
132 This function calculates the cumulative sum along the 1st dimension.
133
134 By using xchg etc. it is possible to use any dimension.
135
136 The sum is started so that the first element in the cumulative sum is
137 the first element of the parameter.
138
139 $a = cumusumover($b);
140
141 $spectrum = cumusumover $image->xchg(0,1)
142
143 dcumusumover
144
145 Signature: (a(n); double [o]b(n))
146
147 Cumulative sum
148
149 This function calculates the cumulative sum along the 1st dimension.
150
151 By using xchg etc. it is possible to use any dimension.
152
153 The sum is started so that the first element in the cumulative sum is
154 the first element of the parameter.
155
156 $a = cumusumover($b);
157
158 $spectrum = cumusumover $image->xchg(0,1)
159
160 Unlike cumusumover, the calculations are performed in double precision.
161
162 orover
163
164 Signature: (a(n); int+ [o]b())
165
166 Project via or to N-1 dimensions
167
168 This function reduces the dimensionality of a piddle by one by taking
169 the or along the 1st dimension.
170
171 By using xchg etc. it is possible to use any dimension.
172
173 $a = orover($b);
174
175 $spectrum = orover $image->xchg(0,1)
176
177 bandover
178
179 Signature: (a(n); int+ [o]b())
180
181 Project via bitwise and to N-1 dimensions
182
183 This function reduces the dimensionality of a piddle by one by taking
184 the bitwise and along the 1st dimension.
185
186 By using xchg etc. it is possible to use any dimension.
187
188 $a = bandover($b);
189
190 $spectrum = bandover $image->xchg(0,1)
191
192 borover
193
194 Signature: (a(n); int+ [o]b())
195
196 Project via bitwise or to N-1 dimensions
197
198 This function reduces the dimensionality of a piddle by one by taking
199 the bitwise or along the 1st dimension.
200
201 By using xchg etc. it is possible to use any dimension.
202
203 $a = borover($b);
204
205 $spectrum = borover $image->xchg(0,1)
206
207 zcover
208
209 Signature: (a(n); int+ [o]b())
210
211 Project via == 0 to N-1 dimensions
212
213 This function reduces the dimensionality of a piddle by one by taking
214 the == 0 along the 1st dimension.
215
216 By using xchg etc. it is possible to use any dimension.
217
218 $a = zcover($b);
219
220 $spectrum = zcover $image->xchg(0,1)
221
222 andover
223
224 Signature: (a(n); int+ [o]b())
225
226 Project via and to N-1 dimensions
227
228 This function reduces the dimensionality of a piddle by one by taking
229 the and along the 1st dimension.
230
231 By using xchg etc. it is possible to use any dimension.
232
233 $a = andover($b);
234
235 $spectrum = andover $image->xchg(0,1)
236
237 intover
238
239 Signature: (a(n); int+ [o]b())
240
241 Project via integral to N-1 dimensions
242
243 This function reduces the dimensionality of a piddle by one by taking
244 the integral along the 1st dimension.
245
246 By using xchg etc. it is possible to use any dimension.
247
248 $a = intover($b);
249
250 $spectrum = intover $image->xchg(0,1)
251
252 Notes:
253
254 For "n > 3", these are all "O(h^4)" (like Simpson's rule), but are
255 integrals between the end points assuming the pdl gives values just at
256 these centres: for such `functions', sumover is correct to O(h), but is
257 the natural (and correct) choice for binned data, of course.
258
259 average
260
261 Signature: (a(n); int+ [o]b())
262
263 Project via average to N-1 dimensions
264
265 This function reduces the dimensionality of a piddle by one by taking
266 the average along the 1st dimension.
267
268 By using xchg etc. it is possible to use any dimension.
269
270 $a = average($b);
271
272 $spectrum = average $image->xchg(0,1)
273
274 daverage
275
276 Signature: (a(n); double [o]b())
277
278 Project via average to N-1 dimensions
279
280 This function reduces the dimensionality of a piddle by one by taking
281 the average along the 1st dimension.
282
283 By using xchg etc. it is possible to use any dimension.
284
285 $a = daverage($b);
286
287 $spectrum = daverage $image->xchg(0,1)
288
289 Unlike average, the calculation is performed in double precision.
290
291 medover
292
293 Signature: (a(n); [o]b(); [t]tmp(n))
294
295 Project via median to N-1 dimensions
296
297 This function reduces the dimensionality of a piddle by one by taking
298 the median along the 1st dimension.
299
300 By using xchg etc. it is possible to use any dimension.
301
302 $a = medover($b);
303
304 $spectrum = medover $image->xchg(0,1)
305
306 oddmedover
307
308 Signature: (a(n); [o]b(); [t]tmp(n))
309
310 Project via oddmedian to N-1 dimensions
311
312 This function reduces the dimensionality of a piddle by one by taking
313 the oddmedian along the 1st dimension.
314
315 By using xchg etc. it is possible to use any dimension.
316
317 $a = oddmedover($b);
318
319 $spectrum = oddmedover $image->xchg(0,1)
320
321 The median is sometimes not a good choice as if the array has an even
322 number of elements it lies half-way between the two middle values -
323 thus it does not always correspond to a data value. The lower-odd
324 median is just the lower of these two values and so it ALWAYS sits on
325 an actual data value which is useful in some circumstances.
326
327 pctover
328
329 Signature: (a(n); p(); [o]b(); [t]tmp(n))
330
331 Project via percentile to N-1 dimensions
332
333 This function reduces the dimensionality of a piddle by one by finding
334 the specified percentile (p) along the 1st dimension. The specified
335 percentile must be between 0.0 and 1.0. When the specified percentile
336 falls between data points, the result is interpolated.
337
338 By using xchg etc. it is possible to use any dimension.
339
340 $a = pctover($b, $p);
341
342 $spectrum = pctover $image->xchg(0,1) $p
343
344 oddpctover
345
346 Signature: (a(n); p(); [o]b(); [t]tmp(n))
347
348 Project via percentile to N-1 dimensions
349
350 This function reduces the dimensionality of a piddle by one by finding
351 the specified percentile along the 1st dimension. The specified per‐
352 centile must be between 0.0 and 1.0. When the specified percentile
353 falls between two values, the nearest data value is the result.
354
355 By using xchg etc. it is possible to use any dimension.
356
357 $a = oddpctover($b, $p);
358
359 $spectrum = oddpctover $image->xchg(0,1) $p
360
361 pct
362
363 Return the specified percentile of all elements in a piddle. The speci‐
364 fied percentile (p) must be between 0.0 and 1.0. When the specified
365 percentile falls between data points, the result is interpolated.
366
367 $x = pct($data, $pct);
368
369 oddpct
370
371 Return the specified percentile of all elements in a piddle. The speci‐
372 fied percentile must be between 0.0 and 1.0. When the specified per‐
373 centile falls between two values, the nearest data value is the result.
374
375 $x = oddpct($data, $pct);
376
377 avg
378
379 Return the average of all elements in a piddle
380
381 $x = avg($data);
382
383 sum
384
385 Return the sum of all elements in a piddle
386
387 $x = sum($data);
388
389 prod
390
391 Return the product of all elements in a piddle
392
393 $x = prod($data);
394
395 davg
396
397 Return the average (in double precision) of all elements in a piddle
398
399 $x = davg($data);
400
401 dsum
402
403 Return the sum (in double precision) of all elements in a piddle
404
405 $x = dsum($data);
406
407 dprod
408
409 Return the product (in double precision) of all elements in a piddle
410
411 $x = dprod($data);
412
413 zcheck
414
415 Return the check for zero of all elements in a piddle
416
417 $x = zcheck($data);
418
419 and
420
421 Return the logical and of all elements in a piddle
422
423 $x = and($data);
424
425 band
426
427 Return the bitwise and of all elements in a piddle
428
429 $x = band($data);
430
431 or
432
433 Return the logical or of all elements in a piddle
434
435 $x = or($data);
436
437 bor
438
439 Return the bitwise or of all elements in a piddle
440
441 $x = bor($data);
442
443 min
444
445 Return the minimum of all elements in a piddle
446
447 $x = min($data);
448
449 max
450
451 Return the maximum of all elements in a piddle
452
453 $x = max($data);
454
455 median
456
457 Return the median of all elements in a piddle
458
459 $x = median($data);
460
461 oddmedian
462
463 Return the oddmedian of all elements in a piddle
464
465 $x = oddmedian($data);
466
467 any
468
469 Return true if any element in piddle set
470
471 Useful in conditional expressions:
472
473 if (any $a>15) { print "some values are greater than 15\n" }
474
475 all
476
477 Return true if all elements in piddle set
478
479 Useful in conditional expressions:
480
481 if (all $a>15) { print "all values are greater than 15\n" }
482
483 minmax
484
485 Returns an array with minimum and maximum values of a piddle.
486
487 ($mn, $mx) = minmax($pdl);
488
489 This routine does not thread over the dimensions of $pdl; it returns
490 the minimum and maximum values of the whole array. See minmaximum if
491 this is not what is required. The two values are returned as Perl
492 scalars similar to min/max.
493
494 perldl> $x = pdl [1,-2,3,5,0]
495 perldl> ($min, $max) = minmax($x);
496 perldl> p "$min $max\n";
497 -2 5
498
499 qsort
500
501 Signature: (a(n); [o]b(n))
502
503 Quicksort a vector into ascending order.
504
505 print qsort random(10);
506
507 qsorti
508
509 Signature: (a(n); int [o]indx(n))
510
511 Quicksort a vector and return index of elements in ascending order.
512
513 $ix = qsorti $a;
514 print $a->index($ix); # Sorted list
515
516 qsortvec
517
518 Signature: (a(n,m); [o]b(n,m))
519
520 Sort a list of vectors lexicographically.
521
522 The 0th dimension of the source piddle is dimension in the vector; the
523 1st dimension is list order. Higher dimensions are threaded over.
524
525 print qsortvec pdl([[1,2],[0,500],[2,3],[4,2],[3,4],[3,5]]);
526 [
527 [ 0 500]
528 [ 1 2]
529 [ 2 3]
530 [ 3 4]
531 [ 3 5]
532 [ 4 2]
533 ]
534
535 minimum
536
537 Signature: (a(n); [o]c())
538
539 Project via minimum to N-1 dimensions
540
541 This function reduces the dimensionality of a piddle by one by taking
542 the minimum along the 1st dimension.
543
544 By using xchg etc. it is possible to use any dimension.
545
546 $a = minimum($b);
547
548 $spectrum = minimum $image->xchg(0,1)
549
550 minimum_ind
551
552 Signature: (a(n); int [o] c())
553
554 Like minimum but returns the index rather than the value
555
556 minimum_n_ind
557
558 Signature: (a(n); int[o]c(m))
559
560 Returns the index of "m" minimum elements
561
562 maximum
563
564 Signature: (a(n); [o]c())
565
566 Project via maximum to N-1 dimensions
567
568 This function reduces the dimensionality of a piddle by one by taking
569 the maximum along the 1st dimension.
570
571 By using xchg etc. it is possible to use any dimension.
572
573 $a = maximum($b);
574
575 $spectrum = maximum $image->xchg(0,1)
576
577 maximum_ind
578
579 Signature: (a(n); int [o] c())
580
581 Like maximum but returns the index rather than the value
582
583 maximum_n_ind
584
585 Signature: (a(n); int[o]c(m))
586
587 Returns the index of "m" maximum elements
588
589 minmaximum
590
591 Signature: (a(n); [o]cmin(); [o] cmax(); int [o]cmin_ind(); int [o]cmax_ind())
592
593 Find minimum and maximum and their indices for a given piddle;
594
595 perldl> $a=pdl [[-2,3,4],[1,0,3]]
596 perldl> ($min, $max, $min_ind, $max_ind)=minmaximum($a)
597 perldl> p $min, $max, $min_ind, $max_ind
598 [-2 0] [4 3] [0 1] [2 2]
599
600 See also minmax, which clumps the piddle together.
601
603 Copyright (C) Tuomas J. Lukka 1997 (lukka@husc.harvard.edu). Contribu‐
604 tions by Christian Soeller (c.soeller@auckland.ac.nz) and Karl Glaze‐
605 brook (kgb@aaoepp.aao.gov.au). All rights reserved. There is no war‐
606 ranty. You are allowed to redistribute this software / documentation
607 under certain conditions. For details, see the file COPYING in the PDL
608 distribution. If this file is separated from the PDL distribution, the
609 copyright notice should be included in the file.
610
611
612
613perl v5.8.8 2006-12-02 Ufunc(3)