Numpy C-Api array_equal

I tried to find a function comparing two PyArrayObject - something like numpy array_equal But I did not find anything. Do you know how this works?

If not - how to import this numpy array_equal into my C code?

+1
source share
1 answer

Here is the code for array_equal:

def array_equal(a1, a2):
    try:
        a1, a2 = asarray(a1), asarray(a2)
    except:
        return False
    if a1.shape != a2.shape:
        return False
    return bool(asarray(a1 == a2).all())

As you can see, this is not a level function c-api. After making sure that both inputs are arrays and that this form matches, it performs a test of the element ==followed by all.

This does not work reliably with floats. This is normal with ints and boolean.

, c-api - , , , .


PyArray_CountNonzero(PyArrayObject* self)

. , , PyArray_Nonzero , . , 2 ( dtype), .

, , . nditer, .

+3

Source: https://habr.com/ru/post/1622016/


All Articles