Numpy Array Get row index searching by a row

后端 未结 1 1650
旧时难觅i
旧时难觅i 2020-12-02 17:30

I am new to numpy and I am implementing clustering with random forest in python. My question is:

How could I find the index of the exact row in an array? For exampl

相关标签:
1条回答
  • 2020-12-02 18:13

    Why not simply do something like this?

    >>> a
    array([[ 0.,  5.,  2.],
           [ 0.,  0.,  3.],
           [ 0.,  0.,  0.]])
    >>> b
    array([ 0.,  0.,  3.])
    
    >>> a==b
    array([[ True, False, False],
           [ True,  True,  True],
           [ True,  True, False]], dtype=bool)
    
    >>> np.all(a==b,axis=1)
    array([False,  True, False], dtype=bool)
    
    >>> np.where(np.all(a==b,axis=1))
    (array([1]),)
    
    0 讨论(0)
提交回复
热议问题