For example, I have an array data = 0 0 0 0 0 0 1 1 1
. I want to get the index of the first non-zero element in the array.
Asked
Active
Viewed 47 times
2 Answers
2
Use the function ifirstHit
. For example:
data = 0 0 0 0 0 0 1 1 1
ifirstHit(ne, data, 0)
Output: 6

dontyousee
- 458
- 2
- 9
1
Find first 1
data.find(1)
Find first non-zero element
data.find(data[data != 0].first())

Hanwei Tang
- 413
- 3
- 10