I have arrays similar to the following:
a=[["tennis","tennis","golf","federer","cricket"],
["federer","nadal","woods","sausage","federer"],
["sausage","lion","prawn","prawn","sausage"]]
I then have a matrix of the following weights
w=[[1,3,3,4,5],
[2,3,2,3,4],
[1,2,1,1,1]]
What I am looking to then do is to sum the weights based on the labels of matrix a for each row and take the top 3 labels from that row. So at the end I would like something like this:
res=[["cricket","tennis","federer"],
["federer","sausage","nadal"],
["lion","sausage","prawn"]]
In my actual data set ties would be highly unlikely and are not really a concern, also for cases where say the entire row is:
["federer","federer","federer","federer","federer"]
Ideally I would like this to be returned as ["federer","",""].
Any guidance would be appreciated.