Python numpy filter two-dimensional array by condition

前端 未结 4 1722
半阙折子戏
半阙折子戏 2020-12-19 03:26

Python newbie here, I have read Filter rows of a numpy array? and the doc but still can\'t figure out how to code it the python way.

Example array I have: (the real

4条回答
  •  独厮守ぢ
    2020-12-19 04:15

    Try this:

    >>> a[numpy.in1d(a[:,1], filter)]
    array([['2', 'a'],
           ['4', 'c']], 
          dtype='|S21')
    

    Also go through http://docs.scipy.org/doc/numpy/reference/generated/numpy.in1d.html

提交回复
热议问题