[Numpy-discussion] Help to process a large data file

David Huard david.huard at gmail.com
Thu Oct 2 09:46:19 EDT 2008


Frank,

How about that:

x = np.loadtxt('file')

z = x.sum(1)   # Reduce data to an array of 0,1,2

rz = z[z>0]   # Remove all 0s since you don't want to count those.

loc = np.where(rz==2)[0]  # The location of the (1,1)s

count = np.diff(loc) - 1  # The spacing between those (1,1)s, ie, the number
of elements that have one 1.


HTH,

David


On Wed, Oct 1, 2008 at 9:27 PM, frank wang <f.yw at hotmail.com> wrote:

>  Hi,
>
> 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:
>
> 1 0
> 0 0
> 1 1
> 0 0
> 0 1    x
> 0 1    x
> 0 0
> 0 1    x
> 1 1
> 0 0
> 0 1    x
> 0 1    x
> 1 1
>
> Then my count will be 3 and 2 (the numbers with x).
>
> Are there an efficient way to do this? My data file is pretty big.
>
> Thanks
>
> Frank
>
> ------------------------------
> See how Windows connects the people, information, and fun that are part of
> your life. See Now<http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20081002/901852c7/attachment.html>


More information about the NumPy-Discussion mailing list