What is the equivalent in python3.6 of the find
of matlab command for this expression? The PDF that I have with some equivalences does not have this command
pos = find(sn_til>0)
What is the equivalent in python3.6 of the find
of matlab command for this expression? The PDF that I have with some equivalences does not have this command
pos = find(sn_til>0)
The find matlab returns the position of the elements that satisfy a particular condition.
A simple way to implement would be:
vals = [1,2,5,64,33,2,4,-1,3,-54,21]
vals_find = [idx for idx, val in enumerate(vals) if val > 0] # armazenamos os indices em que se encontram os valores que satisfazem a condição
print(vals_find) # [0, 1, 2, 3, 4, 5, 6, 8, 10]
Where the condition is val > 0
In matlab the indices start at 1, if you want the result based on that, you can change it to:
vals_find = [idx for idx, val in enumerate(vals, 1) if val > 0]