I have a numpy vector and a numpy array .
I need to take from each row in the matrix the first N (say 3) values that are less than (or equal to) the corresponding row in the vector.
so if this is my vector:
7, 9, 22, 38, 6, 15
and this is my matrix:
[[ 20., 9., 7., 5., None, None], [ 33., 21., 18., 9., 8., 7.], [ 31., 21., 13., 12., 4., 0.], [ 36., 18., 11., 7., 7., 2.], [ 20., 14., 10., 6., 6., 3.], [ 14., 14., 13., 11., 5., 5.]]
the conclusion should be:
[[7,5,None], [9,8,7], [21,13,12], [36,18,11], [6,6,3], 14,14,13]]
Is there an efficient way to do this with masks or something else without an ugly for loop?
Any help would be appreciated!