Robert Robert - 11 months ago 59
Python Question

Testing if all values in a numpy array are equal

I have an numpy one dimensional array c that is supposed to be filled with the contents of

a + b
. I'm first executing
a + b
on a device using

I want to quickly determine the correctness of the result array
in python using numpy slicing.

This is what I currently have

def python_kernel(a, b, c):
temp = a + b
if temp[:] != c[:]:
print "Error"
print "Success!"

But I get the error:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

But it seems
will just determine whether the values aren't 0.

What should I do if I want to test if all of the scalers in the numpy array temp are equal to every value in the numpy array c?

Answer Source

Why not just use numpy.array_equal(a1, a2)[docs] from NumPy's functions?