I need to assert that all numeric values in an array are either negative or non-negative.
I wrote this:
def check(arr):
return all([i < 0 for i in arr]) or all([i >= 0 for i in arr])
And this, which is slightly more efficient I suppose:
def check(arr):
temp = [i < 0 for i in arr]
return all(temp) or not any(temp)
I would like to know if there's a cleaner / more pythonic way, or perhaps some arithmetic trick which I can use instead.