Although I am an experienced C programmer, I am somewhat new to functional programming. Therefore I am a bit embarrassed to ask questions regarding such a simple problem. Any how...
I have a huge list of 0's and 1's (with many more 0's than 1's) with about 10,000 elements. I want to compute all index distances between consecutive 1's, and from that list build an histogram. Any efficient ideas?
For instance: Consider the list L={ 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0}
.
The distances list would be D={ 4, 5, 3 }
.
Differences@Position[1]@L
or take a look atSparseArray
and"Nonzeropositions"
: 100661 $\endgroup$ – Kuba♦ Sep 10 '16 at 11:32