numpy_helper.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:phocnet 作者: ssudholt 项目源码 文件源码
def get_unique_rows(arr, return_indices=False):
        '''
        Returns the unique rows of the supplied array
        this code was originally proposed at stackoverflow
        http://stackoverflow.com/questions/16970982/find-unique-rows-in-numpy-array

        Args:
            arr (2d-ndarray): the array from which to extract the unique rows
            return_indices (bool): if true, the indices corresponding to the unique rows in arr are
                                   returned as well                        
        '''
        b = np.ascontiguousarray(arr).view(np.dtype((np.void, arr.dtype.itemsize * arr.shape[1])))
        _, idx = np.unique(b, return_index=True)

        # return the result
        if return_indices:
            return arr[idx], idx
        else:
            return arr[idx]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号