Check if two numpy arrays are identical

前端 未结 7 987
轻奢々
轻奢々 2020-12-10 15:47

Suppose I have a bunch of arrays, including x and y, and I want to check if they\'re equal. Generally, I can just use np.all(x == y) (

相关标签:
7条回答
  • 2020-12-10 16:50

    Hmmm, I know it is the poor answer but it seems there is no easy way for this. Numpy Creators should fix it. I suggest:

    def compare(a, b):
        if len(a) > 0 and not np.array_equal(a[0], b[0]):
            return False
        if len(a) > 15 and not np.array_equal(a[:15], b[:15]):
            return False
        if len(a) > 200 and not np.array_equal(a[:200], b[:200]):
            return False
        return np.array_equal(a, b)
    

    :)

    0 讨论(0)
提交回复
热议问题