I have a multidimensional NumPy array read from a CSV file. I want to retrieve rows matching a certain column in the data set dynamically.
My current array is
[[LIMS_AY60_51X, AY60_51X_61536153d7cdc55.png, 857.61389, 291.227, NO, 728.322,865.442]
[LIMS_AY60_52X, AY60_52X_615f6r53d7cdc55.png, 867.61389, 292.227, NO, 728.322,865.442]
[LIMS_AY60_53X, AY60_53X_615ft153d7cdc55.png, 877.61389, 293.227, NO, 728.322,865.442]
[LIMS_AY60_54X, AY60_54X_615u6153d7cdc55.png, 818.61389, 294.227, NO, 728.322,865.442]
[LIMS_AY60_55X, AY60_55X_615f615od7cdc55.png, 847.61389, 295.227, NO, 728.322,865.442]......]
I would like to use 'np.where' method to extract the rows matching the criteria as follows : (second column value equal to
'AY60_52X_615f6r53d7cdc55.png'
np.where ((vals == (:,'AY60_52X_615f6r53d7cdc55.png',:,:,:,:,:)).all(axis=1))
This one has an error due to syntax.
File "<ipython-input-31-a28fe9729cd4>", line 3
np.where ((vals == (:,'AY60_52X_615f6r53d7cdc55.png',:,:,:,:,:)).all(axis=1))
^
SyntaxError: invalid syntax
Any help is appreciated
CodePudding user response:
You can do it like this using numpy:
selected_row = a[np.any(a == 'AY60_52X_615f6r53d7cdc55.png', axis=1)]
Output:
>>> selected_row
array([['LIMS_AY60_52X', 'AY60_52X_615f6r53d7cdc55.png', '867.61389', '292.227', 'NO', '728.322', '865.442']], dtype='<U32')