Select certain rows (condition met), but only some columns in Python/Numpy

前端 未结 5 2055
一整个雨季
一整个雨季 2020-12-15 05:29

I have an numpy array with 4 columns and want to select columns 1, 3 and 4, where the value of the second column meets a certain condition (i.e. a fixed value). I tried to f

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 05:46

    >>> a=np.array([[1,2,3], [1,3,4], [2,2,5]])
    >>> a[a[:,0]==1][:,[0,1]]
    array([[1, 2],
           [1, 3]])
    >>> 
    

提交回复
热议问题