<div dir="ltr">Frank, <br><br>How about that:<br><br>x = np.loadtxt('file')<br><br>z = x.sum(1)   # Reduce data to an array of 0,1,2<br><br>rz = z[z>0]   # Remove all 0s since you don't want to count those.<br>
<br>loc = np.where(rz==2)[0]  # The location of the (1,1)s<br><br>count = np.diff(loc) - 1  # The spacing between those (1,1)s, ie, the number of elements that have one 1. <br><br><br>HTH, <br><br>David<br><br><br><div class="gmail_quote">
On Wed, Oct 1, 2008 at 9:27 PM, frank wang <span dir="ltr"><<a href="mailto:f.yw@hotmail.com">f.yw@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">




<div>
Hi, <br>
 <br>
I have a large data file which contains 2 columns of data. The two columns only have zero and one. Now I want to cound how many one in between if both columns are one. For example, if my data is:<br>
 <br>
1 0<br>
0 0<br>
1 1<br>
0 0     <br>
0 1    x<br>
0 1    x<br>
0 0<br>
0 1    x<br>
1 1<br>
0 0<br>
0 1    x<br>
0 1    x<br>
1 1<br>
 <br>
Then my count will be 3 and 2 (the numbers with x).<br>
 <br>
Are there an efficient way to do this? My data file is pretty big.<br>
 <br>
Thanks<br>
 <br>
Frank<br><br><hr>See how Windows connects the people, information, and fun that are part of your life. <a href="http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/" target="_blank">See Now</a></div>
<br>_______________________________________________<br>
Numpy-discussion mailing list<br>
<a href="mailto:Numpy-discussion@scipy.org">Numpy-discussion@scipy.org</a><br>
<a href="http://projects.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://projects.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div>