如何返回一组符合给定条件的NumPy矩阵行?在
这是一个纽比矩阵对象>>> 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')
我想得到第一列值为'rainy'的所有行的集合,所以它尝试了这个方法
^{pr2}$
但我想要这样的输出matrix([['rainy', 'mild', 'high', 'FALSE'],
['rainy', 'cool', 'normal', 'FALSE'],
['rainy', 'cool', 'normal', 'TRUE'],
['rainy', 'mild', 'normal', 'FALSE'],
['rainy', 'mild', 'high', 'TRUE']],
dtype='|S8')
这应该怎么做?在
最后
以上就是无私月饼最近收集整理的关于python矩阵 条件选取行_如何根据一个条件从NumPy矩阵中得到行的子集?的全部内容,更多相关python矩阵内容请搜索靠谱客的其他文章。
发表评论 取消回复