def longest_contiguous_ones(x):
x = np.ravel(x)<EOL>if len(x)==<NUM_LIT:0>:<EOL><INDENT>return np.array([])<EOL><DEDENT>ind = (x==<NUM_LIT:0>).nonzero()[<NUM_LIT:0>]<EOL>if len(ind)==<NUM_LIT:0>:<EOL><INDENT>return np.arange(len(x))<EOL><DEDENT>if len(ind)==len(x):<EOL><INDENT>return np.array([])<EOL><DEDENT>y = np.zeros( (len(x)+<NUM_LIT:2>,), x.dtype)<EOL>y[<NUM_LIT:1>:-<NUM_LIT:1>] = x<EOL>dif = np.diff(y)<EOL>up = (dif ==  <NUM_LIT:1>).nonzero()[<NUM_LIT:0>];<EOL>dn = (dif == -<NUM_LIT:1>).nonzero()[<NUM_LIT:0>];<EOL>i = (dn-up == max(dn - up)).nonzero()[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>ind = np.arange(up[i], dn[i])<EOL>return ind<EOL>
Return the indices of the longest stretch of contiguous ones in *x*,
assuming *x* is a vector of zeros and ones.  If there are two
equally long stretches, pick the first.