Reputation: 121
I want to start an if
condition checking all elements in a previously defined array, for example:
import numpy as np
f = np.zeros(5)
if f[i]<100
#do something
where i
is supposed to check all the elements of f
. I believe there is an easy way to do this in python instead of creating a loop searching all elements, any help would be appreciated. Thanks in advance.
Edit: I tried to use the numpy.any()
function but it seems is not working the way I thought, for example:
import numpy as np
z = np.array([1, 2000, 30000])
if np.any(z)>2:
print('Something')
But the results return False
Upvotes: 0
Views: 226
Reputation: 121
So I've made it with the any
function:
import numpy as np
z = np.array([1, 2000, 3.2e+18])
if (any(x>1000 fo x in z)):
# do something
Upvotes: 1