def singleBlockTrue(array):
    if len(array) == 0:
        return False
transitions = (array[1:] != array[:-1]).sum()
if transitions == 0:
    return array[0]
if transitions == 1:
    return True
if transitions == 2:
    return not array[0]
return False
How can I tell whether a numpy boolean array contains only a single block of `True`s?