How to return a set of rows of a NumPy Matrix that would match a given condition?
This is a Numpy Matrix object
>>> X
matrix([['sunny', 'hot', 'high', 'FALSE'],
['sunny', 'hot', 'high', 'TRUE'],
['overcast', 'hot', 'high', 'FALSE'],
['rainy', 'mild', 'high', 'FALSE'],
['rainy', 'cool', 'normal', 'FALSE'],
['rainy', 'cool', 'normal', 'TRUE'],
['overcast', 'cool', 'normal', 'TRUE'],
['sunny', 'mild', 'high', 'FALSE'],
['sunny', 'cool', 'normal', 'FALSE'],
['rainy', 'mild', 'normal', 'FALSE'],
['sunny', 'mild', 'normal', 'TRUE'],
['overcast', 'mild', 'high', 'TRUE'],
['overcast', 'hot', 'normal', 'FALSE'],
['rainy', 'mild', 'high', 'TRUE']],
dtype='|S8')
I would like to get the set of all rows that has the first column value as 'rainy'
so it tried this
>>> X[X[:,0]=='rainy']
matrix([['rainy', 'rainy', 'rainy', 'rainy', 'rainy']],
dtype='|S8')
But I wanted an output like this
matrix([['rainy', 'mild', 'high', 'FALSE'],
['rainy', 'cool', 'normal', 'FALSE'],
['rainy', 'cool', 'normal', 'TRUE'],
['rainy', 'mild', 'normal', 'FALSE'],
['rainy', 'mild', 'high', 'TRUE']],
dtype='|S8')
How should this be done?