check for identical rows in different numpy arrays

后端 未结 6 812
无人共我
无人共我 2020-11-28 15:14

how do I get a row-wise comparison between two arrays, in the result of a row-wise true/false array?

Given datas:

a = np.array([[1,0],[2,0],[3,1],[         


        
6条回答
  •  误落风尘
    2020-11-28 16:06

    you can use numpy with apply_along_axis (kind of iteration on specific axis while axis=0 iterate on every cell, axis=1 iterate on every row, axis=2 on matrix and so on

    import numpy as np
    a = np.array([[1,0],[2,0],[3,1],[4,2]])
    b = np.array([[1,0],[2,0],[4,2]])
    c = np.apply_along_axis(lambda x,y: x in y, 1, a, b)
    

提交回复
热议问题