0

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.

winnie
  • 183
  • 1
  • 6

2 Answers2

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