getRandomDiff¶
-
lsst.validate.drp.util.
getRandomDiff
(array)[source]¶ Get the difference between two randomly selected elements of an array.
Returns: float or int
Difference between two random elements of the array.
Notes
- As implemented the returned value is the result of subtracting
two elements of the input array. In all of the imagined uses that’s going to be a scalar (float, maybe int). In principle, however the code as implemented returns the result of subtracting two elements of the array, which could be any arbitrary object that is the result of the subtraction operator applied to two elements of the array.
- This is not the most efficient way to extract a pair,
but it’s the easiest to write.
- Shuffling works correctly for low N (even N=2), where a naive
random generation of entries would result in duplicates.
- In principle it might be more efficient to shuffle the indices,
then extract the difference. But this probably only would make a difference for arrays whose elements were objects that were substantially larger than a float. And that would only make sense for objects that had a subtraction operation defined.