Selecting rows from a NumPy ndarray

前端 未结 4 1100
[愿得一人]
[愿得一人] 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:36

    numpy.in1d is what you are looking for:

    print test[numpy.in1d(test[:,1], wanted)]
    

    It should easily be the fastest solution if wanted is large; plus, it is the most readable one, id say.

提交回复
热议问题