I am calculating the absolute difference between two numpy.uint8s in python with
d = abs(a - b), which results in an overflow error if b is bigger than a. What’s the best way to avoid this?
I am calculating the absolute difference between two numpy.uint8 s in python with d
Share
As your comment indicates, they aren’t
ints; they’renumpy.uint8s. Just convert them toints:Since you are concerned about speed, here are a couple of tests (borrowing Sven‘s form, with thanks):
So yes, it’s faster, but unless we’re talking about doing it hundreds of millions of times, it won’t matter a bit.