Problems while applying multiple conditions to validate an array?

I am receiving a number of arrays like this:

arr1 = np.asarray([41, 183, 101, 1607, 70, 137])

arr2 = np.asarray([300, 250, 300, 17, 300, 190])

arr3 = np.asarray([41, 10, 60, 1207, 70, 137])

Which I am validating with this function:

def check(arr):
    if arr[ arr >= 90 ].size >= 4:
        return 'maybe'
    elif arr[ arr >= 250 ].size >= 4:
        return 'yes'
    elif arr[ arr < 90 ].size >= 4:
        return 'no'

The condition that I would like to apply is, if at least 4 elements of the array are greater than 90, return "maybe", at the same time if at least 4 elements are greater than 250 the array should be "yes". Finally, if less than 4 elements are greater than 90, I should return "no".

I tried to apply the above function and even np.where. Nevertheless, the function is not working for arr2, as it is returning maybe instead of yes. What is the correct and pythonic (one-liner) way of checking multiple conditions over these arrays?



Read more here: https://stackoverflow.com/questions/66994775/problems-while-applying-multiple-conditions-to-validate-an-array

Content Attribution

This content was originally published by tumbleweed at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: