Selecting rows from a NumPy ndarray

前端 未结 4 1097
[愿得一人]
[愿得一人] 2021-01-31 18:32

I want to select only certain rows from a NumPy array based on the value in the second column. For example, this test array has integers from 1 to 10 in the second column.

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 18:35

    test[numpy.logical_or.reduce([test[:,1] == x for x in wanted])]
    

    The result should be faster than the original version since NumPy's doing the inner loops instead of Python.

提交回复
热议问题