i have an array of boolean variables. The array has a sort of structure, it's formed of many sequences of zeros and ones, sequences of different length. such as:
[1111111100001111111111000000000000001111111000000111111111111111110000]
"commas omitted between values"
i need to separate it in this way
[111111110000],[111111111100000000000000],[1111111000000],[111111111111111110000]
Someone knows a good way or just a way to do this ?
Algorithm could be language free, but in case you know how to do it in python you are welcome.
After some struggling i found a way to divide the array, but only if it begins with ONES. I realy can't figure out how to make it work with array beginning with 1 or 0.
import numpy as np
x = np.asarray([1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0])
c = 1
for i in range(len(x)):
if x[i] == 1:
if c == 0:
print "\n\tDIVIDE\n"
c = 1
print "one"
else:
if c == 1:
c = 0
print "zero"
0. Do you then want all the result arrays to lead with0, or do you want the first array to only have0? – Mark Hurd May 15 '15 at 05:19