Florida Man
Florida Man

Reputation: 2157

Indexing a list with another list which contains arrays

Dear forum I want to index a patient data list with an annotation list where every element is an nx1 array.

Patient List: e.g. 10 patients, 20 features, 300 datapoints (each element of the list is an 300x20 array) Annotation List: e.g. 10 patients, 300 annotations

The aim is to create a list with patient values where the values are chosen by:

With the help of this great forum I managed to choose the patients and the features (F1,F2,F3) with:

 F1=5;F2=13;F3=74     
 selected_babies =[0,1,2]
 Xfeat=[val[:,(F1,F2,F3)] for sb, val in enumerate(Patient_Matrix) if sb in selected_babies] #selecting top three fearues F1 F2 F3 datapoints

Then I create a list with the indices which correspond with the annotations I want. In this case 1 and 2.

label=array([1,2])
idx=[in1d(Annottions[sb],label) for sb in selected_babies]
idx=[nonzero(idx[sb])[0] for sb in selected_babies] # get the indices where True

As said, the idx is now a List with 3 elements (due to selected_babies), where each element is a array of n values which indicates the indices of the data I want to use. Now I would like to use this list to choose my data from the created Xfeat. Until now it contains all values for feature F1,F2 and F3. I want only the 1 and 2 annotated values for F1,F2,F3 of the selected_ babies.

I tried:

Xfeat=[val[idx[sb],:] for sb, val in enumerate(Patient_Matrix) if sb in selected_babies]    #selecting the datapoints in label

But it does not work. IndexError: index 0 is out of bounds for axis 0 with size 0.

Does anyone know how to do this correct?

Thanks a lot for your help in advance.

Upvotes: 3

Views: 85

Answers (1)

Florida Man
Florida Man

Reputation: 2157

I seems to work with this:

Xfeat=[val[idx[sb],:] for sb, val in enumerate(Xfeat) if sb in selected_babies]

I still get the indexError, but only for a certain patient. I will have to figure out what happens there. Hope I could help someone.

Cheers

Upvotes: 1

Related Questions