Your aversion to a nested loop for this (together with the genomics question) makes it sound like you might use
R, where nested loops are laughed at due to their inefficiency relative to applying functions across an entire array/matrix/etc.. If this is the case, you could use
Statistics::R to easily interface with R since what you want to do is trivial in R.
That being said, how long does it actually take you to do what you want using a nested loop? You could try to incorporate map which may give you modest savings vs a for loop.