I am defining a function in Python that needs to check
if a==b:
do.stuff()
In principle, a and b could be numpy arrays or integers, and I would like my implementation to be robust against this. However, to check equality for a numpy array, one needs to append the boolean with all(), which will break the code when a and b are integers.
Is there a simple way to code the equality test so that it works regardless of whether a and b are integers or numpy arrays?
type()?allon the comparison isn't even correct for arrays - you'll get a variety of false positives and exceptions when the arrays have mismatched shapes.anyorall, usinganyorallis very rarely the right move when you get one of those exceptions. Usually the right move is something likenumpy.whereornumpy.array_equal.)