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 Signature: (a(n); int+ [o]b())
25
26 Project via product to N-1 dimensions
27
28 This function reduces the dimensionality of an ndarray by one by taking
29 the product along the 1st dimension.
30
31 By using xchg etc. it is possible to use any dimension.
32
33 $y = prodover($x);
34
35 $spectrum = prodover $image->transpose
36
37 prodover processes bad values. It will set the bad-value flag of all
38 output ndarrays if the flag is set for any of the input ndarrays.
39
40 cprodover
41 Signature: (a(n); cdouble [o]b())
42
43 Project via product to N-1 dimensions
44
45 This function reduces the dimensionality of an ndarray by one by taking
46 the product along the 1st dimension.
47
48 By using xchg etc. it is possible to use any dimension.
49
50 $y = cprodover($x);
51
52 $spectrum = cprodover $image->transpose
53
54 Unlike "prodover", the calculations are performed in complex double
55 precision.
56
57 cprodover processes bad values. It will set the bad-value flag of all
58 output ndarrays if the flag is set for any of the input ndarrays.
59
60 dprodover
61 Signature: (a(n); double [o]b())
62
63 Project via product to N-1 dimensions
64
65 This function reduces the dimensionality of an ndarray by one by taking
66 the product along the 1st dimension.
67
68 By using xchg etc. it is possible to use any dimension.
69
70 $y = dprodover($x);
71
72 $spectrum = dprodover $image->transpose
73
74 Unlike "prodover", the calculations are performed in double precision.
75
76 dprodover processes bad values. It will set the bad-value flag of all
77 output ndarrays if the flag is set for any of the input ndarrays.
78
79 cumuprodover
80 Signature: (a(n); int+ [o]b(n))
81
82 Cumulative product
83
84 This function calculates the cumulative product along the 1st
85 dimension.
86
87 By using xchg etc. it is possible to use any dimension.
88
89 The sum is started so that the first element in the cumulative product
90 is the first element of the parameter.
91
92 $y = cumuprodover($x);
93
94 $spectrum = cumuprodover $image->transpose
95
96 cumuprodover processes bad values. It will set the bad-value flag of
97 all output ndarrays if the flag is set for any of the input ndarrays.
98
99 dcumuprodover
100 Signature: (a(n); double [o]b(n))
101
102 Cumulative product
103
104 This function calculates the cumulative product along the 1st
105 dimension.
106
107 By using xchg etc. it is possible to use any dimension.
108
109 The sum is started so that the first element in the cumulative product
110 is the first element of the parameter.
111
112 $y = dcumuprodover($x);
113
114 $spectrum = dcumuprodover $image->transpose
115
116 Unlike "cumuprodover", the calculations are performed in double
117 precision.
118
119 dcumuprodover processes bad values. It will set the bad-value flag of
120 all output ndarrays if the flag is set for any of the input ndarrays.
121
122 sumover
123 Signature: (a(n); int+ [o]b())
124
125 Project via sum to N-1 dimensions
126
127 This function reduces the dimensionality of an ndarray by one by taking
128 the sum along the 1st dimension.
129
130 By using xchg etc. it is possible to use any dimension.
131
132 $y = sumover($x);
133
134 $spectrum = sumover $image->transpose
135
136 sumover processes bad values. It will set the bad-value flag of all
137 output ndarrays if the flag is set for any of the input ndarrays.
138
139 csumover
140 Signature: (a(n); cdouble [o]b())
141
142 Project via sum to N-1 dimensions
143
144 This function reduces the dimensionality of an ndarray by one by taking
145 the sum along the 1st dimension.
146
147 By using xchg etc. it is possible to use any dimension.
148
149 $y = csumover($x);
150
151 $spectrum = csumover $image->transpose
152
153 Unlike "sumover", the calculations are performed in complex double
154 precision.
155
156 csumover processes bad values. It will set the bad-value flag of all
157 output ndarrays if the flag is set for any of the input ndarrays.
158
159 dsumover
160 Signature: (a(n); double [o]b())
161
162 Project via sum to N-1 dimensions
163
164 This function reduces the dimensionality of an ndarray by one by taking
165 the sum along the 1st dimension.
166
167 By using xchg etc. it is possible to use any dimension.
168
169 $y = dsumover($x);
170
171 $spectrum = dsumover $image->transpose
172
173 Unlike "sumover", the calculations are performed in double precision.
174
175 dsumover processes bad values. It will set the bad-value flag of all
176 output ndarrays if the flag is set for any of the input ndarrays.
177
178 cumusumover
179 Signature: (a(n); int+ [o]b(n))
180
181 Cumulative sum
182
183 This function calculates the cumulative sum along the 1st dimension.
184
185 By using xchg etc. it is possible to use any dimension.
186
187 The sum is started so that the first element in the cumulative sum is
188 the first element of the parameter.
189
190 $y = cumusumover($x);
191
192 $spectrum = cumusumover $image->transpose
193
194 cumusumover processes bad values. It will set the bad-value flag of
195 all output ndarrays if the flag is set for any of the input ndarrays.
196
197 dcumusumover
198 Signature: (a(n); double [o]b(n))
199
200 Cumulative sum
201
202 This function calculates the cumulative sum along the 1st dimension.
203
204 By using xchg etc. it is possible to use any dimension.
205
206 The sum is started so that the first element in the cumulative sum is
207 the first element of the parameter.
208
209 $y = dcumusumover($x);
210
211 $spectrum = dcumusumover $image->transpose
212
213 Unlike "cumusumover", the calculations are performed in double
214 precision.
215
216 dcumusumover processes bad values. It will set the bad-value flag of
217 all output ndarrays if the flag is set for any of the input ndarrays.
218
219 andover
220 Signature: (a(n); int+ [o]b())
221
222 Project via and to N-1 dimensions
223
224 This function reduces the dimensionality of an ndarray by one by taking
225 the and along the 1st dimension.
226
227 By using xchg etc. it is possible to use any dimension.
228
229 $y = andover($x);
230
231 $spectrum = andover $image->transpose
232
233 If a() contains only bad data (and its bad flag is set), b() is set
234 bad. Otherwise b() will have its bad flag cleared, as it will not
235 contain any bad values.
236
237 bandover
238 Signature: (a(n); [o]b())
239
240 Project via bitwise and to N-1 dimensions
241
242 This function reduces the dimensionality of an ndarray by one by taking
243 the bitwise and along the 1st dimension.
244
245 By using xchg etc. it is possible to use any dimension.
246
247 $y = bandover($x);
248
249 $spectrum = bandover $image->transpose
250
251 If a() contains only bad data (and its bad flag is set), b() is set
252 bad. Otherwise b() will have its bad flag cleared, as it will not
253 contain any bad values.
254
255 borover
256 Signature: (a(n); [o]b())
257
258 Project via bitwise or to N-1 dimensions
259
260 This function reduces the dimensionality of an ndarray by one by taking
261 the bitwise or along the 1st dimension.
262
263 By using xchg etc. it is possible to use any dimension.
264
265 $y = borover($x);
266
267 $spectrum = borover $image->transpose
268
269 If a() contains only bad data (and its bad flag is set), b() is set
270 bad. Otherwise b() will have its bad flag cleared, as it will not
271 contain any bad values.
272
273 orover
274 Signature: (a(n); int+ [o]b())
275
276 Project via or to N-1 dimensions
277
278 This function reduces the dimensionality of an ndarray by one by taking
279 the or along the 1st dimension.
280
281 By using xchg etc. it is possible to use any dimension.
282
283 $y = orover($x);
284
285 $spectrum = orover $image->transpose
286
287 If a() contains only bad data (and its bad flag is set), b() is set
288 bad. Otherwise b() will have its bad flag cleared, as it will not
289 contain any bad values.
290
291 zcover
292 Signature: (a(n); int+ [o]b())
293
294 Project via == 0 to N-1 dimensions
295
296 This function reduces the dimensionality of an ndarray by one by taking
297 the == 0 along the 1st dimension.
298
299 By using xchg etc. it is possible to use any dimension.
300
301 $y = zcover($x);
302
303 $spectrum = zcover $image->transpose
304
305 If a() contains only bad data (and its bad flag is set), b() is set
306 bad. Otherwise b() will have its bad flag cleared, as it will not
307 contain any bad values.
308
309 intover
310 Signature: (a(n); float+ [o]b())
311
312 Project via integral to N-1 dimensions
313
314 This function reduces the dimensionality of an ndarray by one by taking
315 the integral along the 1st dimension.
316
317 By using xchg etc. it is possible to use any dimension.
318
319 $y = intover($x);
320
321 $spectrum = intover $image->transpose
322
323 Notes:
324
325 "intover" uses a point spacing of one (i.e., delta-h==1). You will
326 need to scale the result to correct for the true point delta).
327
328 For "n > 3", these are all O(h^4) (like Simpson's rule), but are
329 integrals between the end points assuming the pdl gives values just at
330 these centres: for such `functions', sumover is correct to O(h), but is
331 the natural (and correct) choice for binned data, of course.
332
333 intover ignores the bad-value flag of the input ndarrays. It will set
334 the bad-value flag of all output ndarrays if the flag is set for any of
335 the input ndarrays.
336
337 average
338 Signature: (a(n); int+ [o]b())
339
340 Project via average to N-1 dimensions
341
342 This function reduces the dimensionality of an ndarray by one by taking
343 the average along the 1st dimension.
344
345 By using xchg etc. it is possible to use any dimension.
346
347 $y = average($x);
348
349 $spectrum = average $image->transpose
350
351 average processes bad values. It will set the bad-value flag of all
352 output ndarrays if the flag is set for any of the input ndarrays.
353
354 avgover
355 Synonym for average.
356
357 caverage
358 Signature: (a(n); cdouble [o]b())
359
360 Project via average to N-1 dimensions
361
362 This function reduces the dimensionality of an ndarray by one by taking
363 the average along the 1st dimension.
364
365 By using xchg etc. it is possible to use any dimension.
366
367 $y = caverage($x);
368
369 $spectrum = caverage $image->transpose
370
371 Unlike average, the calculation is performed in complex double
372 precision.
373
374 caverage processes bad values. It will set the bad-value flag of all
375 output ndarrays if the flag is set for any of the input ndarrays.
376
377 cavgover
378 Synonym for caverage.
379
380 daverage
381 Signature: (a(n); double [o]b())
382
383 Project via average to N-1 dimensions
384
385 This function reduces the dimensionality of an ndarray by one by taking
386 the average along the 1st dimension.
387
388 By using xchg etc. it is possible to use any dimension.
389
390 $y = daverage($x);
391
392 $spectrum = daverage $image->transpose
393
394 Unlike average, the calculation is performed in double precision.
395
396 daverage processes bad values. It will set the bad-value flag of all
397 output ndarrays if the flag is set for any of the input ndarrays.
398
399 davgover
400 Synonym for daverage.
401
402 minimum
403 Signature: (a(n); [o]c())
404
405 Project via minimum to N-1 dimensions
406
407 This function reduces the dimensionality of an ndarray by one by taking
408 the minimum along the 1st dimension.
409
410 By using xchg etc. it is possible to use any dimension.
411
412 $y = minimum($x);
413
414 $spectrum = minimum $image->transpose
415
416 Output is set bad if no elements of the input are non-bad, otherwise
417 the bad flag is cleared for the output ndarray.
418
419 Note that "NaNs" are considered to be valid values and will "win" over
420 non-"NaN"; see isfinite and badmask for ways of masking NaNs.
421
422 minover
423 Synonym for minimum.
424
425 minimum_ind
426 Signature: (a(n); indx [o] c())
427
428 Like minimum but returns the index rather than the value
429
430 Output is set bad if no elements of the input are non-bad, otherwise
431 the bad flag is cleared for the output ndarray.
432
433 Note that "NaNs" are considered to be valid values and will "win" over
434 non-"NaN"; see isfinite and badmask for ways of masking NaNs.
435
436 minover_ind
437 Synonym for minimum_ind.
438
439 minimum_n_ind
440 Signature: (a(n); indx [o]c(m); PDL_Indx m_size => m)
441
442 Returns the index of "m_size" minimum elements. As of 2.077, you can
443 specify how many by either passing in an ndarray of the given size
444 (DEPRECATED - will be converted to indx if needed and the input arg
445 will be set to that), or just the size, or a null and the size.
446
447 minimum_n_ind($pdl, $out = zeroes(5)); # DEPRECATED
448 $out = minimum_n_ind($pdl, 5);
449 minimum_n_ind($pdl, $out = null, 5);
450
451 Output bad flag is cleared for the output ndarray if sufficient non-bad
452 elements found, else remaining slots in $c() are set bad.
453
454 Note that "NaNs" are considered to be valid values and will "win" over
455 non-"NaN"; see isfinite and badmask for ways of masking NaNs.
456
457 minover_n_ind
458 Synonym for minimum_n_ind.
459
460 maximum
461 Signature: (a(n); [o]c())
462
463 Project via maximum to N-1 dimensions
464
465 This function reduces the dimensionality of an ndarray by one by taking
466 the maximum along the 1st dimension.
467
468 By using xchg etc. it is possible to use any dimension.
469
470 $y = maximum($x);
471
472 $spectrum = maximum $image->transpose
473
474 Output is set bad if no elements of the input are non-bad, otherwise
475 the bad flag is cleared for the output ndarray.
476
477 Note that "NaNs" are considered to be valid values and will "win" over
478 non-"NaN"; see isfinite and badmask for ways of masking NaNs.
479
480 maxover
481 Synonym for maximum.
482
483 maximum_ind
484 Signature: (a(n); indx [o] c())
485
486 Like maximum but returns the index rather than the value
487
488 Output is set bad if no elements of the input are non-bad, otherwise
489 the bad flag is cleared for the output ndarray.
490
491 Note that "NaNs" are considered to be valid values and will "win" over
492 non-"NaN"; see isfinite and badmask for ways of masking NaNs.
493
494 maxover_ind
495 Synonym for maximum_ind.
496
497 maximum_n_ind
498 Signature: (a(n); indx [o]c(m); PDL_Indx m_size => m)
499
500 Returns the index of "m_size" maximum elements. As of 2.077, you can
501 specify how many by either passing in an ndarray of the given size
502 (DEPRECATED - will be converted to indx if needed and the input arg
503 will be set to that), or just the size, or a null and the size.
504
505 maximum_n_ind($pdl, $out = zeroes(5)); # DEPRECATED
506 $out = maximum_n_ind($pdl, 5);
507 maximum_n_ind($pdl, $out = null, 5);
508
509 Output bad flag is cleared for the output ndarray if sufficient non-bad
510 elements found, else remaining slots in $c() are set bad.
511
512 Note that "NaNs" are considered to be valid values and will "win" over
513 non-"NaN"; see isfinite and badmask for ways of masking NaNs.
514
515 maxover_n_ind
516 Synonym for maximum_n_ind.
517
518 minmaximum
519 Signature: (a(n); [o]cmin(); [o] cmax(); indx [o]cmin_ind(); indx [o]cmax_ind())
520
521 Find minimum and maximum and their indices for a given ndarray;
522
523 pdl> $x=pdl [[-2,3,4],[1,0,3]]
524 pdl> ($min, $max, $min_ind, $max_ind)=minmaximum($x)
525 pdl> p $min, $max, $min_ind, $max_ind
526 [-2 0] [4 3] [0 1] [2 2]
527
528 See also "minmax", which clumps the ndarray together.
529
530 If a() contains only bad data, then the output ndarrays will be set
531 bad, along with their bad flag. Otherwise they will have their bad
532 flags cleared, since they will not contain any bad values.
533
534 minmaxover
535 Synonym for minmaximum.
536
537 avg
538 Return the average of all elements in an ndarray.
539
540 See the documentation for "average" for more information.
541
542 $x = avg($data);
543
544 This routine handles bad values.
545
546 sum
547 Return the sum of all elements in an ndarray.
548
549 See the documentation for "sumover" for more information.
550
551 $x = sum($data);
552
553 This routine handles bad values.
554
555 prod
556 Return the product of all elements in an ndarray.
557
558 See the documentation for "prodover" for more information.
559
560 $x = prod($data);
561
562 This routine handles bad values.
563
564 davg
565 Return the average (in double precision) of all elements in an ndarray.
566
567 See the documentation for "daverage" for more information.
568
569 $x = davg($data);
570
571 This routine handles bad values.
572
573 dsum
574 Return the sum (in double precision) of all elements in an ndarray.
575
576 See the documentation for "dsumover" for more information.
577
578 $x = dsum($data);
579
580 This routine handles bad values.
581
582 dprod
583 Return the product (in double precision) of all elements in an ndarray.
584
585 See the documentation for "dprodover" for more information.
586
587 $x = dprod($data);
588
589 This routine handles bad values.
590
591 zcheck
592 Return the check for zero of all elements in an ndarray.
593
594 See the documentation for "zcover" for more information.
595
596 $x = zcheck($data);
597
598 This routine handles bad values.
599
600 and
601 Return the logical and of all elements in an ndarray.
602
603 See the documentation for "andover" for more information.
604
605 $x = and($data);
606
607 This routine handles bad values.
608
609 band
610 Return the bitwise and of all elements in an ndarray.
611
612 See the documentation for "bandover" for more information.
613
614 $x = band($data);
615
616 This routine handles bad values.
617
618 or
619 Return the logical or of all elements in an ndarray.
620
621 See the documentation for "orover" for more information.
622
623 $x = or($data);
624
625 This routine handles bad values.
626
627 bor
628 Return the bitwise or of all elements in an ndarray.
629
630 See the documentation for "borover" for more information.
631
632 $x = bor($data);
633
634 This routine handles bad values.
635
636 min
637 Return the minimum of all elements in an ndarray.
638
639 See the documentation for "minimum" for more information.
640
641 $x = min($data);
642
643 This routine handles bad values.
644
645 max
646 Return the maximum of all elements in an ndarray.
647
648 See the documentation for "maximum" for more information.
649
650 $x = max($data);
651
652 This routine handles bad values.
653
654 median
655 Return the median of all elements in an ndarray.
656
657 See the documentation for "medover" for more information.
658
659 $x = median($data);
660
661 This routine handles bad values.
662
663 mode
664 Return the mode of all elements in an ndarray.
665
666 See the documentation for "modeover" for more information.
667
668 $x = mode($data);
669
670 This routine handles bad values.
671
672 oddmedian
673 Return the oddmedian of all elements in an ndarray.
674
675 See the documentation for "oddmedover" for more information.
676
677 $x = oddmedian($data);
678
679 This routine handles bad values.
680
681 any
682 Return true if any element in ndarray set
683
684 Useful in conditional expressions:
685
686 if (any $x>15) { print "some values are greater than 15\n" }
687
688 See "or" for comments on what happens when all elements in the check
689 are bad.
690
691 all
692 Return true if all elements in ndarray set
693
694 Useful in conditional expressions:
695
696 if (all $x>15) { print "all values are greater than 15\n" }
697
698 See "and" for comments on what happens when all elements in the check
699 are bad.
700
701 minmax
702 Returns a list with minimum and maximum values of an ndarray.
703
704 ($mn, $mx) = minmax($pdl);
705
706 This routine does not broadcast over the dimensions of $pdl; it returns
707 the minimum and maximum values of the whole ndarray. See "minmaximum"
708 if this is not what is required. The two values are returned as Perl
709 scalars, and therefore ignore whether the values are bad.
710
711 pdl> $x = pdl [1,-2,3,5,0]
712 pdl> ($min, $max) = minmax($x);
713 pdl> p "$min $max\n";
714 -2 5
715
716 medover
717 Signature: (a(n); [o]b(); [t]tmp(n))
718
719 Project via median to N-1 dimensions
720
721 This function reduces the dimensionality of an ndarray by one by taking
722 the median along the 1st dimension.
723
724 By using xchg etc. it is possible to use any dimension.
725
726 $y = medover($x);
727
728 $spectrum = medover $image->transpose
729
730 medover processes bad values. It will set the bad-value flag of all
731 output ndarrays if the flag is set for any of the input ndarrays.
732
733 oddmedover
734 Signature: (a(n); [o]b(); [t]tmp(n))
735
736 Project via oddmedian to N-1 dimensions
737
738 This function reduces the dimensionality of an ndarray by one by taking
739 the oddmedian along the 1st dimension.
740
741 By using xchg etc. it is possible to use any dimension.
742
743 $y = oddmedover($x);
744
745 $spectrum = oddmedover $image->transpose
746
747 The median is sometimes not a good choice as if the array has an even
748 number of elements it lies half-way between the two middle values -
749 thus it does not always correspond to a data value. The lower-odd
750 median is just the lower of these two values and so it ALWAYS sits on
751 an actual data value which is useful in some circumstances.
752
753 oddmedover processes bad values. It will set the bad-value flag of all
754 output ndarrays if the flag is set for any of the input ndarrays.
755
756 modeover
757 Signature: (data(n); [o]out(); [t]sorted(n))
758
759 Project via mode to N-1 dimensions
760
761 This function reduces the dimensionality of an ndarray by one by taking
762 the mode along the 1st dimension.
763
764 By using xchg etc. it is possible to use any dimension.
765
766 $y = modeover($x);
767
768 $spectrum = modeover $image->transpose
769
770 The mode is the single element most frequently found in a discrete data
771 set.
772
773 It only makes sense for integer data types, since floating-point types
774 are demoted to integer before the mode is calculated.
775
776 "modeover" treats BAD the same as any other value: if BAD is the most
777 common element, the returned value is also BAD.
778
779 modeover does not process bad values. It will set the bad-value flag
780 of all output ndarrays if the flag is set for any of the input
781 ndarrays.
782
783 pctover
784 Signature: (a(n); p(); [o]b(); [t]tmp(n))
785
786 Project via specified percentile to N-1 dimensions
787
788 This function reduces the dimensionality of an ndarray by one by taking
789 the specified percentile along the 1st dimension.
790
791 By using xchg etc. it is possible to use any dimension.
792
793 $y = pctover($x);
794
795 $spectrum = pctover $image->transpose
796
797 The specified percentile must be between 0.0 and 1.0. When the
798 specified percentile falls between data points, the result is
799 interpolated. Values outside the allowed range are clipped to 0.0 or
800 1.0 respectively. The algorithm implemented here is based on the
801 interpolation variant described at
802 <http://en.wikipedia.org/wiki/Percentile> as used by Microsoft Excel
803 and recommended by NIST.
804
805 pctover processes bad values. It will set the bad-value flag of all
806 output ndarrays if the flag is set for any of the input ndarrays.
807
808 oddpctover
809 Signature: (a(n); p(); [o]b(); [t]tmp(n))
810
811 Project via specified percentile to N-1 dimensions
812
813 This function reduces the dimensionality of an ndarray by one by taking
814 the specified percentile along the 1st dimension.
815
816 By using xchg etc. it is possible to use any dimension.
817
818 $y = oddpctover($x);
819
820 $spectrum = oddpctover $image->transpose
821
822 The specified percentile must be between 0.0 and 1.0. When the
823 specified percentile falls between two values, the nearest data value
824 is the result. The algorithm implemented is from the textbook version
825 described first at <http://en.wikipedia.org/wiki/Percentile>.
826
827 oddpctover processes bad values. It will set the bad-value flag of all
828 output ndarrays if the flag is set for any of the input ndarrays.
829
830 pct
831 Return the specified percentile of all elements in an ndarray. The
832 specified percentile (p) must be between 0.0 and 1.0. When the
833 specified percentile falls between data points, the result is
834 interpolated.
835
836 $x = pct($data, $pct);
837
838 oddpct
839 Return the specified percentile of all elements in an ndarray. The
840 specified percentile (p) must be between 0.0 and 1.0. When the
841 specified percentile falls between data points, the nearest data value
842 is the result.
843
844 $x = oddpct($data, $pct);
845
846 qsort
847 Signature: (a(n); [o]b(n))
848
849 Quicksort a vector into ascending order.
850
851 print qsort random(10);
852
853 Bad values are moved to the end of the array:
854
855 pdl> p $y
856 [42 47 98 BAD 22 96 74 41 79 76 96 BAD 32 76 25 59 BAD 96 32 BAD]
857 pdl> p qsort($y)
858 [22 25 32 32 41 42 47 59 74 76 76 79 96 96 96 98 BAD BAD BAD BAD]
859
860 qsorti
861 Signature: (a(n); indx [o]indx(n))
862
863 Quicksort a vector and return index of elements in ascending order.
864
865 $ix = qsorti $x;
866 print $x->index($ix); # Sorted list
867
868 Bad elements are moved to the end of the array:
869
870 pdl> p $y
871 [42 47 98 BAD 22 96 74 41 79 76 96 BAD 32 76 25 59 BAD 96 32 BAD]
872 pdl> p $y->index( qsorti($y) )
873 [22 25 32 32 41 42 47 59 74 76 76 79 96 96 96 98 BAD BAD BAD BAD]
874
875 qsortvec
876 Signature: (a(n,m); [o]b(n,m))
877
878 Sort a list of vectors lexicographically.
879
880 The 0th dimension of the source ndarray is dimension in the vector; the
881 1st dimension is list order. Higher dimensions are broadcasted over.
882
883 print qsortvec pdl([[1,2],[0,500],[2,3],[4,2],[3,4],[3,5]]);
884 [
885 [ 0 500]
886 [ 1 2]
887 [ 2 3]
888 [ 3 4]
889 [ 3 5]
890 [ 4 2]
891 ]
892
893 Vectors with bad components are moved to the end of the array:
894
895 pdl> p $p = pdl("[0 0] [-100 0] [BAD 0] [100 0]")->qsortvec
896
897 [
898 [-100 0]
899 [ 0 0]
900 [ 100 0]
901 [ BAD 0]
902 ]
903
904 qsortveci
905 Signature: (a(n,m); indx [o]indx(m))
906
907 Sort a list of vectors lexicographically, returning the indices of the
908 sorted vectors rather than the sorted list itself.
909
910 As with "qsortvec", the input PDL should be an NxM array containing M
911 separate N-dimensional vectors. The return value is an integer M-PDL
912 containing the M-indices of original array rows, in sorted order.
913
914 As with "qsortvec", the zeroth element of the vectors runs slowest in
915 the sorted list.
916
917 Additional dimensions are broadcasted over: each plane is sorted
918 separately, so qsortveci may be thought of as a collapse operator of
919 sorts (groan).
920
921 Vectors with bad components are moved to the end of the array as for
922 "qsortvec".
923
925 Copyright (C) Tuomas J. Lukka 1997 (lukka@husc.harvard.edu).
926 Contributions by Christian Soeller (c.soeller@auckland.ac.nz) and Karl
927 Glazebrook (kgb@aaoepp.aao.gov.au). All rights reserved. There is no
928 warranty. You are allowed to redistribute this software / documentation
929 under certain conditions. For details, see the file COPYING in the PDL
930 distribution. If this file is separated from the PDL distribution, the
931 copyright notice should be included in the file.
932
933
934
935perl v5.36.0 2023-01-20 Ufunc(3)