If you add a number to an array slot that takes it outside of it's datatype range, it will loop around past the range and back to zero. Example with uint8, whose max range is 255:
z = np.zeros(2, dtype=np.uint8)
z[0]=z[0]+267
print(z[0])
> 11
I would like to prevent any addition which makes the slot loop back to zero.
I came up with this function
def ifAdd( addCand, numb):
if addCand+numb >255:
return
else:
addCand = addCand + numb
ifAdd(z[0], 267)
I am wondering if there is a more pythonic of numpthonic way of doing this. Or at the least, a more computationally more efficient method.