Selecting data based on label

Hello,

I have a vector of values

image

And a vector of labels

(image1)

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

(image2)

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

(image3)

Because I’m a new user I can only post one picture. Here’s the rest : https://imgur.com/a/MUJ5tcw

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,