Perl PDL - Getting 80% of the Lowest Vector Values

Is there an elegant PDL function that gets a list of values ​​and returns a list of 80% of the original values, which are the lowest?

For example: If I have a list like this: (9, 4, 1, 2, 7, 8, 3, 5, 6, 10)

I would like to get (1, 2, 3, 4, 5, 6, 7, 8) after calling this function in the original list (the order of the values ​​doesn't matter - it doesn't need to sort the values).

I found PDL :: Ufunc :: oddpct which can return the 80th percentile, but I would like to get a list of values ​​before this percentile. I can do it myself, but if there is something out of the box - why not use it?

Thanks!!!

+4
source share
3 answers

I suggest you use pct to get the number of the 80th percentile in combination with the where primitive to select everything below this value. Using your own data, it looks like

 use strict; use warnings; use PDL; my $list = pdl(9, 4, 1, 2, 7, 8, 3, 5, 6, 10); print qsort $list->where($list <= $list->pct(80/100)); 

OUTPUT

 [1 2 3 4 5 6 7 8] 
+5
source

Well, it's a do-it-yourself thing that you don’t want to do, but it's that simple. It seems that PDL is hard for this.

 use strict; use warnings; my @list = (9, 4, 1, 2, 7, 8, 3, 5, 6, 10); my @slist = sort {$a <=> $b} @list; my @list80 = @slist[0..int(0.8*@slist)-1]; print "@list80"; 
0
source

Not PDL, but most likely at least:

Statistics :: CaseResampling select_kth Function

0
source

Source: https://habr.com/ru/post/1399153/


All Articles