vendredi 1 juillet 2016

Find indices in array for multiple values


How to get the index of values in an array (a) by a another array (label) with more than one "markers"? I tried several combinations. None of the following seems to work. label = array([1, 2]) a = array([1, 1, 2, 2, 3, 3]) idx = where(a==label) # gives me only the index of the last value in label idx = where(a==label[0] or label[1]) # Is confused by all or any? idx = where(a==label[0] | label[1]) # gives me results as if nor. idx = [4,5] idx = where(a==label[0] || label[1]) # syntax error idx = where(a==bolean.or(label,0,1) # I know, this is not the correct form but I don`t remember it correctly but remember the error: also asks for a.all or a.any idx = where(label[0] or label[1] in a) # gives me only the first appearance. index = 0. Also without where(). idx = where(a==label[0] or a==label[1]).all()) # syntax error idx = where(a.any(0,label[0] or label[1])) # gives me only the first appearance. index=0. Also without where(). idx = where(a.any(0,label[0] | label[1])) # gives me only the first appearance. index=0. Also without where(). idx=where(a.any(0,label)) # Datatype not understood Ok, I think you get my problem. Does anyone know how to do it correctly? Best would be a solution with a general label instead of label[x] so that the use of label is more variable for later changes.

Aucun commentaire:

Enregistrer un commentaire