Ufunc(3pm)

πŸ“¦
version 2.085 Β· 4 versions
, in ubuntu noble

πŸ’– PDL::Ufunc πŸ’–

okay bestie, sit down, hydrate, and let me tell you about PDL::Ufunc β€” the Perl module that's giving primitive ufunc operations for pdl. Periodt.


✨ NAME ✨

PDL::Ufunc β€” primitive ufunc operations for pdl πŸ¦‹


🌸 DESCRIPTION 🌸

So this module is literally serving you a whole collection of primitive and useful functions, all defined with PDL::PP, based on the functionality of what people sometimes call ufuncs (like, NumPY and Mathematica talk about these, iykyk). It gathers up all the functions that get used to "reduce" or "accumulate" along a dimension. πŸŽ€

The way these work? They all do their thing across the first dimension, but bestie, if you use the slicing functions you can absolutely do it on any dimension. Main character energy: you pick the axis. πŸ’…

Also, the PDL::Reduce module gives you an alternative interface to a lot of the functions in this module, so keep that in mind. πŸ‘‘


⭐ SYNOPSIS ⭐

 use PDL::Ufunc;

That's it, that's the whole vibe check. ✨


🌟 FUNCTIONS 🌟

πŸ“ prodover

Signature: (a(n); int+ [o]b())

Project via product to N-1 dimensions.

This one reduces the dimensionality of an ndarray by one by taking the product along the 1st dimension. Lowkey so satisfying. πŸ’–

And by using xchg etc. it is possible to use any dimension β€” you're not locked in, bestie.

 $y = prodover($x);

 $spectrum = prodover $image->transpose

prodover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 🫢

πŸ“ cprodover

Signature: (a(n); cdouble [o]b())

Project via product to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the product along the 1st dimension. Same iconic energy as before. 🌈

By using xchg etc. it is possible to use any dimension.

 $y = cprodover($x);

 $spectrum = cprodover $image->transpose

Unlike "prodover", the calculations are performed in complex double precision. Fancy, I know. πŸ’…

cprodover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. πŸ’œ

πŸ“ dprodover

Signature: (a(n); double [o]b())

Project via product to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the product along the 1st dimension.

By using xchg etc. it is possible to use any dimension. Slay. ✨

 $y = dprodover($x);

 $spectrum = dprodover $image->transpose

Unlike "prodover", the calculations are performed in double precision.

dprodover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 🌸

πŸ¦‹ cumuprodover

Signature: (a(n); int+ [o]b(n))

Cumulative product.

This function calculates the cumulative product along the 1st dimension. It's giving running-total-but-make-it-multiplication. πŸŽ€

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. (Yes, it says "sum", that's just how it is, don't @ me.) 😭

 $y = cumuprodover($x);

 $spectrum = cumuprodover $image->transpose

cumuprodover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. πŸ’–

πŸ¦‹ dcumuprodover

Signature: (a(n); double [o]b(n))

Cumulative product.

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.

 $y = dcumuprodover($x);

 $spectrum = dcumuprodover $image->transpose

Unlike "cumuprodover", the calculations are performed in double precision.

dcumuprodover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 🫢

πŸ”₯ sumover

Signature: (a(n); int+ [o]b())

Project via sum to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the sum along the 1st dimension. The classic. The blueprint. πŸ”₯

By using xchg etc. it is possible to use any dimension.

 $y = sumover($x);

 $spectrum = sumover $image->transpose

sumover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. πŸ’œ

πŸ”₯ csumover

Signature: (a(n); cdouble [o]b())

Project via sum to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the sum along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = csumover($x);

 $spectrum = csumover $image->transpose

Unlike "sumover", the calculations are performed in complex double precision. ✨

csumover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 🌈

πŸ”₯ dsumover

Signature: (a(n); double [o]b())

Project via sum to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the sum along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = dsumover($x);

 $spectrum = dsumover $image->transpose

Unlike "sumover", the calculations are performed in double precision.

dsumover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. πŸ’–

🧚 cumusumover

Signature: (a(n); int+ [o]b(n))

Cumulative sum.

Calculates the cumulative sum along the 1st dimension. Running total, but make it serve. πŸ‘‘

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.

 $y = cumusumover($x);

 $spectrum = cumusumover $image->transpose

cumusumover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 🫢

🧚 dcumusumover

Signature: (a(n); double [o]b(n))

Cumulative sum.

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.

 $y = dcumusumover($x);

 $spectrum = dcumusumover $image->transpose

Unlike "cumusumover", the calculations are performed in double precision.

dcumusumover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. πŸ’œ

🌸 andover

Signature: (a(n); int+ [o]b())

Project via and to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the and along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = andover($x);

 $spectrum = andover $image->transpose

Heads up bestie: if a() contains only bad data (and its bad flag is set), b() is set bad. Otherwise b() will have its bad flag cleared, as it will not contain any bad values. So like, it's not passing the badness along. 🫢

🌸 bandover

Signature: (a(n);  [o]b())

Project via bitwise and to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the bitwise and along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = bandover($x);

 $spectrum = bandover $image->transpose

Same rule as above: if a() contains only bad data (and its bad flag is set), b() is set bad. Otherwise b() will have its bad flag cleared, as it will not contain any bad values. ✨

🌈 borover

Signature: (a(n);  [o]b())

Project via bitwise or to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the bitwise or along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = borover($x);

 $spectrum = borover $image->transpose

And again: if a() contains only bad data (and its bad flag is set), b() is set bad. Otherwise b() will have its bad flag cleared, as it will not contain any bad values. πŸŽ€

🌈 orover

Signature: (a(n); int+ [o]b())

Project via or to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the or along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = orover($x);

 $spectrum = orover $image->transpose

You know the drill: if a() contains only bad data (and its bad flag is set), b() is set bad. Otherwise b() will have its bad flag cleared, as it will not contain any bad values. πŸ’–

πŸ’… zcover

Signature: (a(n); int+ [o]b())

Project via == 0 to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the == 0 along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = zcover($x);

 $spectrum = zcover $image->transpose

Once more for the people in the back: if a() contains only bad data (and its bad flag is set), b() is set bad. Otherwise b() will have its bad flag cleared, as it will not contain any bad values. πŸ‘‘

πŸ¦‹ intover

Signature: (a(n); float+ [o]b())

Project via integral to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the integral along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = intover($x);

 $spectrum = intover $image->transpose

Notes, because this one has lore: πŸ“

  • "intover" uses a point spacing of one (i.e., delta-h==1). You will need to scale the result to correct for the true point delta).
  • 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.
⚠️ Careful bestie: intover ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. πŸ™ˆ

πŸ“ average

Signature: (a(n); int+ [o]b())

Project via average to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the average along the 1st dimension. She's the mean girl (affectionate). πŸ’…

By using xchg etc. it is possible to use any dimension.

 $y = average($x);

 $spectrum = average $image->transpose

average processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 🌸

πŸ“ avgover

Synonym for average. Literally the same function wearing a different outfit. ✨

πŸ’œ caverage

Signature: (a(n); cdouble [o]b())

Project via average to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the average along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = caverage($x);

 $spectrum = caverage $image->transpose

Unlike average, the calculation is performed in complex double precision.

caverage processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 🫢

πŸ’œ cavgover

Synonym for caverage. Same girl, different name tag. πŸŽ€

🌈 daverage

Signature: (a(n); double [o]b())

Project via average to N-1 dimensions.

Reduces the dimensionality of an ndarray by one by taking the average along the 1st dimension.

By using xchg etc. it is possible to use any dimension.

 $y = daverage($x);

 $spectrum = daverage $image->transpose

And bestie, we're not done yet β€” there's more coming in the next part. Stay tuned. πŸ’–

Unlike average, this one does the whole math in double precision. Yes bestie, extra precision, we love to see it πŸ’…

daverage handles bad values, no drama. It'll set the bad-value flag on all the output ndarrays if that flag is set on any of the input ndarrays. That's just how it rolls.

davgover πŸ¦‹

Literally just a synonym for daverage. Same vibes, different name.

minimum 🌸

Signature:

(a(n); [o]c())

Project via minimum down to N-1 dimensions. It shrinks your ndarray's dimensionality by one by grabbing the minimum along the 1st dimension. So slay.

And psst β€” by using xchg and friends, you can do this on any dimension you want. Queen of flexibility πŸ‘‘

 $y = minimum($x);

 $spectrum = minimum $image->transpose

The output gets set bad if no elements of the input are non-bad. Otherwise the bad flag gets cleared for the output ndarray. Simple as.

Heads up: "NaNs" count as valid values here, and they will "win" over non-"NaN" β€” so if you need to mask those gremlins out, go look at isfinite and badmask. iykyk.

minover ✨

Synonym for minimum. That's it, that's the whole section.

minimum_ind πŸ’–

Signature:

(a(n); indx [o] c())

Like minimum but it hands you back the index instead of the value. No cap, that's the only difference.

Output is set bad if no elements of the input are non-bad, otherwise the bad flag is cleared for the output ndarray.

Again: "NaNs" are considered valid values and will "win" over non-"NaN"; check out isfinite and badmask for ways of masking NaNs.

minover_ind πŸŽ€

Synonym for minimum_ind. Periodt.

minimum_n_ind ⭐

Signature:

(a(n); indx [o]c(m); PDL_Indx m_size => m)

Returns the index of "m_size" minimum elements. As of 2.077, you can say how many you want by either passing in an ndarray of the given size β€” which is DEPRECATED, it'll be converted to indx if needed and the input arg will be set to that β€” or just the size, or a null plus the size. Pick your fighter:

 minimum_n_ind($pdl, $out = zeroes(5)); # DEPRECATED
 $out = minimum_n_ind($pdl, 5);
 minimum_n_ind($pdl, $out = null, 5);

The output bad flag gets cleared for the output ndarray if enough non-bad elements are found; otherwise the remaining slots in $c() get set bad. 😭

And one more time for the people in the back: "NaNs" are valid values and will "win" over non-"NaN"; see isfinite and badmask for masking them.

minover_n_ind 🧚

Synonym for minimum_n_ind.

maximum πŸ’œ

Signature:

(a(n); [o]c())

Project via maximum to N-1 dimensions. Reduces your ndarray's dimensionality by one by taking the maximum along the 1st dimension. Main character energy fr fr.

xchg etc. lets you work on any dimension you like.

 $y = maximum($x);

 $spectrum = maximum $image->transpose

Output is set bad if no elements of the input are non-bad, otherwise the bad flag is cleared for the output ndarray.

"NaNs" are valid values and will "win" over non-"NaN"; see isfinite and badmask for ways of masking NaNs.

maxover 🌈

Synonym for maximum.

maximum_ind πŸ”₯

Signature:

(a(n); indx [o] c())

Like maximum but returns the index rather than the value. Iconic behaviour.

Output is set bad if no elements of the input are non-bad, otherwise the bad flag is cleared for the output ndarray.

"NaNs" = valid values, they "win" over non-"NaN"; see isfinite and badmask for masking NaNs.

maxover_ind πŸ‘‘

Synonym for maximum_ind.

maximum_n_ind πŸ“

Signature:

(a(n); indx [o]c(m); PDL_Indx m_size => m)

Returns the index of "m_size" maximum elements. As of 2.077, you specify how many by either passing in an ndarray of the given size (DEPRECATED β€” it'll be converted to indx if needed and the input arg will be set to that), or just the size, or a null and the size:

 maximum_n_ind($pdl, $out = zeroes(5)); # DEPRECATED
 $out = maximum_n_ind($pdl, 5);
 maximum_n_ind($pdl, $out = null, 5);

Output bad flag is cleared for the output ndarray if sufficient non-bad elements are found, else the remaining slots in $c() are set bad.

"NaNs" are valid values and will "win" over non-"NaN"; see isfinite and badmask for ways of masking NaNs.

maxover_n_ind 🫢

Synonym for maximum_n_ind.

minmaximum πŸ’€

Signature:

(a(n); [o]cmin(); [o] cmax(); indx [o]cmin_ind(); indx [o]cmax_ind())

Finds the minimum and maximum and their indices for a given ndarray. Two for one, we ate:

 pdl> $x=pdl [[-2,3,4],[1,0,3]]
 pdl> ($min, $max, $min_ind, $max_ind)=minmaximum($x)
 pdl> p $min, $max, $min_ind, $max_ind
 [-2 0] [4 3] [0 1] [2 2]

Also see "minmax", which clumps the ndarray together instead.

If a() contains only bad data, then the output ndarrays get set bad, along with their bad flag. Otherwise they have their bad flags cleared, since they won't contain any bad values at all. Clean.

minmaxover πŸ™ˆ

Synonym for minmaximum.

avg 🌟

Returns the average of all elements in an ndarray.

Peep the docs for "average" for more info.

 $x = avg($data);

This routine handles bad values. πŸ’ͺ

sum ✨

Returns the sum of all elements in an ndarray.

See the documentation for "sumover" for more information.

 $x = sum($data);

This routine handles bad values.

prod 🌸

Returns the product of all elements in an ndarray.

See the documentation for "prodover" for more information.

 $x = prod($data);

This routine handles bad values.

davg πŸ¦‹

Returns the average (in double precision) of all elements in an ndarray.

See the documentation for "daverage" for more information.

 $x = davg($data);

This routine handles bad values.

dsum πŸ’–

Returns the sum (in double precision) of all elements in an ndarray.

See the documentation for "dsumover" for more information.

 $x = dsum($data);

This routine handles bad values.

dprod πŸŽ€

Returns the product (in double precision) of all elements in an ndarray.

See the documentation for "dprodover" for more information.

 $x = dprod($data);

This routine handles bad values.

zcheck ⭐

Returns the check for zero of all elements in an ndarray.

See the documentation for "zcover" for more information.

 $x = zcheck($data);

This routine handles bad values.

and πŸ’œ

Returns the logical and of all elements in an ndarray.

See the documentation for "andover" for more information.

 $x = and($data);

This routine handles bad values.

band πŸ”₯

Returns the bitwise and of all elements in an ndarray.

See the documentation for "bandover" for more information.

 $x = band($data);

This routine handles bad values.

or 🌈

Returns the logical or of all elements in an ndarray.

See the documentation for "orover" for more information.

 $x = or($data);

This routine handles bad values.

bor πŸ‘‘

Returns the bitwise or of all elements in an ndarray.

See the documentation for "borover" for more information.

 $x = bor($data);

This routine handles bad values.

min πŸ“

Returns the minimum of all elements in an ndarray.

See the documentation for "minimum" for more information.

 $x = min($data);

This routine handles bad values.

max 🧚

Returns the maximum of all elements in an ndarray.

See the documentation for "maximum" for more information.

 $x = max($data);

This routine handles bad values.

median πŸ’…

Returns the median of all elements in an ndarray.

See the documentation for "medover" for more information.

 $x = median($data);

This routine handles bad values.

mode 🌟

Returns the mode of all elements in an ndarray.

See the documentation for "modeover" for more information.

 $x = mode($data);

This routine handles bad values.

oddmedian 🫢

Returns the oddmedian of all elements in an ndarray.

See the documentation for "oddmedover" for more information.

 $x = oddmedian($data);

This routine handles bad values.

any πŸ’€

Returns true if any element in the ndarray is set. Super useful in conditional expressions:

 if (any $x>15) { print "some values are greater than 15\n" }

See "or" for comments on what happens when all elements in the check are bad.

all ✨

Returns true if all elements in the ndarray are set. Also great for conditionals:

 if (all $x>15) { print "all values are greater than 15\n" }

See "and" for comments on what happens when all elements in the check are bad.

minmax 🌸

Returns a list with the minimum and maximum values of an ndarray.

 ($mn, $mx) = minmax($pdl);

Quick note bestie: this routine does not broadcast over the dimensions of $pdl β€” it returns the min and max of the whole ndarray. If that's not what you wanted, go see "minmaximum" instead. The two values come back as Perl scalars, and therefore they ignore whether the values are bad. πŸ™ƒ

 pdl> $x = pdl [1,-2,3,5,0]
 pdl> ($min, $max) = minmax($x);
 pdl> p "$min $max\n";
 -2 5

medover πŸ¦‹

Signature:

(a(n); [o]b(); [t]tmp(n))

Project via median to N-1 dimensions. It drops your ndarray's dimensionality by one by taking the median along the 1st dimension.

Use xchg etc. and you can do it along any dimension. Versatile queen.

 $y = medover($x);

 $spectrum = medover $image->transpose

medover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

oddmedover πŸ’–

Signature:

(a(n); [o]b(); [t]tmp(n))

Project via oddmedian to N-1 dimensions. Reduces your ndarray's dimensionality by one by taking the oddmedian along the 1st dimension.

xchg etc. = any dimension you want, always.

 $y = oddmedover($x);

 $spectrum = oddmedover $image->transpose

Okay so why does this exist? The median is sometimes not a good choice because if the array has an even number of elements, it sits half-way between the two middle values β€” so it doesn't always correspond to an actual data value. The lower-odd median is just the lower of those two values, so it ALWAYS sits on a real data value. Which is useful in some circumstances. Slay.

oddmedover processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

modeover ⭐

Signature:

(data(n); [o]out(); [t]sorted(n))

Project via mode to N-1 dimensions. Yep, it reduces dimensionality by one by taking the mode along the 1st dimension.

xchg etc. β†’ any dimension, as always.

 $y = modeover($x);

 $spectrum = modeover $image->transpose

The mode is the single element most frequently found in a discrete data set.

It only makes sense for integer data types, because floating-point types get demoted to integer before the mode is calculated. So don't come at it with floats, bestie.

"modeover" treats BAD the same as any other value: if BAD is the most common element, the returned value is also BAD. 😭

modeover does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

pctover πŸŽ€

Signature:

(a(n); p(); [o]b(); [t]tmp(n))

Project via specified percentile to N-1 dimensions. Reduces the dimensionality of an ndarray by one by taking the specified percentile along the 1st dimension.

And yes β€” xchg etc. lets you use any dimension.

 $y = pctover($x);

okay so if you wanna pull a percentile along a dimension, you do:

$spectrum = pctover $image->transpose

The percentile you pass has to be between 0.0 and 1.0. If it lands between data points, the result gets interpolated. Values outside the allowed range get clipped to 0.0 or 1.0 respectively. The algorithm here is the interpolation variant described at <http://en.wikipedia.org/wiki/Percentile> β€” the one Microsoft Excel uses and NIST recommends.

pctover processes bad values. It sets the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.


oddpctover πŸ¦‹

Signature: (a(n); p(); [o]b(); [t]tmp(n))

Project via a specified percentile down to N-1 dimensions. This one drops an ndarray's dimensionality by one, taking the specified percentile along the 1st dimension.

You can use xchg etc. to make it work on any dimension.

$y = oddpctover($x);
$spectrum = oddpctover $image->transpose

The percentile you ask for has to be between 0.0 and 1.0. When it falls between two values, the nearest data value is the result. The algorithm implemented is from the textbook version described first at <http://en.wikipedia.org/wiki/Percentile>.

oddpctover processes bad values. It sets the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.


pct ✨

Returns the specified percentile of all elements in an ndarray. The percentile (p) has to be between 0.0 and 1.0. If it falls between data points, the result is interpolated.

$x = pct($data, $pct);

oddpct πŸŽ€

Returns the specified percentile of all elements in an ndarray. The percentile (p) has to be between 0.0 and 1.0. If it falls between data points, the nearest data value is the result.

$x = oddpct($data, $pct);

qsort πŸ’…

Signature: (a(n); [o]b(n))

Quicksorts a vector into ascending order.

print qsort random(10);

Bad values get moved to the end of the array:

pdl> p $y
[42 47 98 BAD 22 96 74 41 79 76 96 BAD 32 76 25 59 BAD 96 32 BAD]
pdl> p qsort($y)
[22 25 32 32 41 42 47 59 74 76 76 79 96 96 96 98 BAD BAD BAD BAD]

qsorti πŸ”₯

Signature: (a(n); indx [o]indx(n))

Quicksorts a vector and returns the index of elements in ascending order.

$ix = qsorti $x;
print $x->index($ix); # Sorted list

Bad elements get moved to the end of the array:

pdl> p $y
[42 47 98 BAD 22 96 74 41 79 76 96 BAD 32 76 25 59 BAD 96 32 BAD]
pdl> p $y->index( qsorti($y) )
[22 25 32 32 41 42 47 59 74 76 76 79 96 96 96 98 BAD BAD BAD BAD]

qsortvec πŸ‘‘

Signature: (a(n,m); [o]b(n,m))

Sorts a list of vectors lexicographically.

The 0th dimension of the source ndarray is the dimension inside the vector; the 1st dimension is list order. Higher dimensions are broadcasted 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]
]

Vectors with bad components get moved to the end of the array:

pdl> p $p = pdl("[0 0] [-100 0] [BAD 0] [100 0]")->qsortvec

[
 [-100    0]
 [   0    0]
 [ 100    0]
 [ BAD    0]
]

qsortveci 🌈

Signature: (a(n,m); indx [o]indx(m))

Sorts a list of vectors lexicographically, but returns the indices of the sorted vectors instead of the sorted list itself.

Like qsortvec, the input PDL should be an NxM array containing M separate N-dimensional vectors. The return value is an integer M-PDL containing the M-indices of original array rows, in sorted order.

Same as qsortvec, the zeroth element of the vectors runs slowest in the sorted list.

Additional dimensions are broadcasted over: each plane is sorted separately, so qsortveci may be thought of as a collapse operator of sorts (groan).

Vectors with bad components get moved to the end of the array as for qsortvec.


πŸ‘‘ AUTHOR πŸ‘‘

Copyright (C) Tuomas J. Lukka 1997 (lukka@husc.harvard.edu). Contributions by Christian Soeller (c.soeller@auckland.ac.nz) and Karl Glazebrook (kgb@aaoepp.aao.gov.au). All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file.


That's the whole vibe, bestie. This page is from perl v5.38.2, dated 2024-04-10, and it's Ufunc(3pm). Stay iconic! πŸ’–βœ¨

πŸ“¦ where this page comes from