I think this is an easy question for experienced numpy users.
I have a score matrix. The raw index corresponds to samples and column index corresponds to items. For example,
score_matrix =
[[ 1. , 0.3, 0.4],
[ 0.2, 0.6, 0.8],
[ 0.1, 0.3, 0.5]]
I want to get top-M indices of items for each samples. Also I want to get top-M scores. For example,
top2_ind =
[[0, 2],
[2, 1],
[2, 1]]
top2_score =
[[1. , 0.4],
[0,8, 0.6],
[0.5, 0.3]]
What is the best way to do this using numpy?
np.argpartition docsstate that to keep the order, we need to provide it a sequence of ints, which I think would be range of those indices, i.e.range(N)insidenp.argpartition(). Were you using any such thing there? Sorry if I missed that!argsortversion.runtime test, whereNis significantly smaller than the axis length.