0

I have a 10 x 1 array made with 1s and 0s like below:

1
1 1
2 0
3 1
4 1
5 1
6 0
7 1
8 0
9 0
10 1

Using for loop, how can I count only 1s from the above array and create a new array? I'm not sure how to explain this in words. Basically, I want to create something like this:

1
1 1
2 3
3 4
4 5
5 7
6 10
  • 4
    I think your "expected" result is wrong (6->7), but you basically want to `find` the indexes of the locations of non-zero values. So use `find()` – Ander Biguri Oct 13 '22 at 18:33

0 Answers0