Is there a clean pythonic (Python 3.6) way to achieve
(arr[0] > 1) & (arr[1] > 1) & (arr[2] > 1) & ... & (arr[N - 1] > 1)
for any array arr with arr.shape = (N, M)
?
Is there a clean pythonic (Python 3.6) way to achieve
(arr[0] > 1) & (arr[1] > 1) & (arr[2] > 1) & ... & (arr[N - 1] > 1)
for any array arr with arr.shape = (N, M)
?
For an array with only 1 row, you can do something like:
arr = [1, 2, 4, 5]
import functools
functools.reduce(lambda a, b: a & b, [(arr[x] > 1) for x in range(0, len(arr))])
However, an explicit for loop, instead of using reduce, might be better for readability.
For an array with more than 1 row, the concept remain the same:
arr = [[1, 2, 4, 5], [231, 542]]
import functools
functools.reduce(lambda a, b: a & b, [(arr[x][y] > 1) for x in range(0, len(arr)) for y in range(0, len(arr[x]))])