Selecting data based on label


I have a vector of values


And a vector of labels


And a set of set of values, that I will call ‘results’


Is there anyway I can fill all of the results s_i such that


Because I’m a new user I can only post one picture. Here’s the rest :

Here’s an example ->

v = [1,2,3,4]
u = [1,1,2,3]

f(u,v) = S

S_1 = [1,2]
S_2 = [3]
S_3 = [4]

I know I can do this using for loops, but I’d like to work with greater amount of data, for which their references are calculated on the spot (not done by a human beforehand) and it is taking too much time with for loops…

Thank. If there’s anything that is unclear about my query, please feel free to ask.

Best regards,